Page 1 of 1

help needed plz

Posted: Thu Feb 16, 2012 3:47 pm
by Henning12342
Hi Guys im trying to get a code that would allow me to increase my attack and my defence using items i have purchased

my data base for items is playershipweapons
and the data base i am trying to increase stats is playerships

ive been trying to get it sorted for a week now but cant get it working any help will be Greatly appretiated thanks

Re: help needed plz

Posted: Thu Feb 16, 2012 4:20 pm
by Chris
My advice would be not to store that information, rather calucalte it when it's needed.

Code: Select all

$shipQuery = mysql_query("SELECT * FROM `playerships` WHERE `id` = 1"); // id = ships id
$shipData = mysql_fetch_assoc($shipQuery);

$totalAttack = $shipData['attack'];
$totalDefence = $shipData['defence'];

$equipmentQuery= mysql_query("SELECT * FROM `playershipweapons` WHERE `equipped` = 1");
while( $equipmentArray = mysql_fetch_assoc($shipEquipmentQuery) )
{
    $totalAttack += $equipmentArray['attack_bonus'];
    $totalDefence += $equipmentArray['defence_bonus'];
}

echo 'attack bonus: ' . $totalAttack . '<br />';
echo 'defence bonus: ' . $totalDefence;