Jump to content


Photo

im stumped *solved*


  • Please log in to reply
4 replies to this topic

#1 xxhopeful

xxhopeful
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 22 September 2006 - 03:24 PM

i've been working on an equine sim game, and i'm trying to create a script that will pull the horses from the database that are on a certain team. then it will take the statistic (also from the database) and add all their statistic together to make one total score. i am unsure about how to create the script so it adds each individual horses score together, as right now i can only get it to add one of their scores. let me know if you have any ideas! thanks!

#2 dragonusthei

dragonusthei
  • Members
  • PipPipPip
  • Advanced Member
  • 46 posts

Posted 22 September 2006 - 03:27 PM

urm..

i would just get the number of horses from the database then do a for loop with the number of horses adding each horses score together

#3 xxhopeful

xxhopeful
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 22 September 2006 - 03:32 PM

this is the current script i have, but all it does is add ONE of the horses scores together..not all of the horses scores:
$querryss=mysql_query("SELECT talent,conformation,strength,agility,conformation,endurance,intelligence,speed,trainedin,gender,name,hid from horses where drivingteam='$drivingteamid'")or die(mysql_error());
      $numss=mysql_num_rows($querryss);

if($numss == "0"){
print "No horses on this team.";
exit;
}

      for($i=0; $i<$numss; $i++){

                $hrowedd=mysql_fetch_array($querryss);

$teamscore=$hrowedd[talent]+$hrowedd[conformation]+$hrowedd[strength]+$hrowedd[agility]+$hrowedd[endurance]+$hrowedd[intelligence]+$hrowedd[speed]+$hrowedd[talent]+$hrowedd[conformation]+$hrowedd[strength]+$hrowedd[agility]+$hrowedd[endurance]+$hrowedd[intelligence]+$hrowedd[speed];
}


#4 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 22 September 2006 - 07:21 PM

<?php
$teamscore = 0;
for($i=0; $i<$numss; $i++){

      $hrowedd=mysql_fetch_array($querryss);

      $teamscore += $hrowedd[talent] + hrowedd[conformation] + $hrowedd[strength] + $hrowedd[agility] +
          $hrowedd[endurance] + $hrowedd[intelligence] + $hrowedd[speed] ;
}
echo $teamscore;
?>

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#5 xxhopeful

xxhopeful
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 22 September 2006 - 08:28 PM

i got it, thanks for the help Barand!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users