help needed plz

Place for questions and answers for all newcomers and new coders. This is a free for all forum, no question is too stupid and to noob.
Post Reply
Henning12342
Posts: 9
Joined: Fri Feb 03, 2012 2:29 pm

help needed plz

Post 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
User avatar
Chris
Posts: 1580
Joined: Wed Sep 30, 2009 7:22 pm

Re: help needed plz

Post 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; 
Fighting for peace is declaring war on war. If you want peace be peaceful.
Post Reply

Return to “Beginner Help and Support”