Heya peeps!
I have a question on a problem that Im having getting my nested for statemenst to work properly.
Ok basically i have a couple of pages that perform some mathmatical calcs that aren't working properly. I need some advice on how to get them to work properly.... plzzzzzzzzzzzzz 😃 .
Here is the page that retireves the submitted results and displays the results of the calcs.
http://www.tswn.com/modules/Mechwarrior/compare.php?compare%5B%5D=47&number%5B%5D=1&compare%5B%5D=31&number%5B%5D=1&compare%5B%5D=71&number%5B%5D=1
If you look at the bottom where it displays the results of the calcs you will see 2 different numbers. One is based on the checked boxes only. It reads the weapon damage results from the database for each displayed weapon and adds them up and displays them. The second one is the one I'm having trouble with. Basically what I would like it to do is take the value for each weapon for weapon damage, multiply it by the dropdown value, and add the total up for all of the weapons displayed. I have code for it now, but its not working right. Here is the code that I have so far. Oh, and if you only select 1 weapon it works fine. It only hiccups when you have more that one item in the array(s).
This is the for statements along with the query.
<?php
print_r($_REQUEST['number']);
$number_count=count($number);
for ($i=0; $i<$number_count; $i++){
$weapon_number = $number[$i];}
/////////////////////////////////////////////////////
$totaldamage=0;
$weapons_count=count($compare);
for ($n=0; $n<$weapons_count; $n++){
$wid=$compare[$n];
mysql_select_db($database_xoops_tswn, $xoops_tswn);
$query_xoops_weapons = "SELECT * FROM xoops_mechwarrior_weapons WHERE wid = '$wid'";
$xoops_weapons = mysql_query($query_xoops_weapons, $xoops_tswn) or die(mysql_error());
$row_xoops_weapons = mysql_fetch_assoc($xoops_weapons);
$totalRows_xoops_weapons = mysql_num_rows($xoops_weapons);
$rawdamage = $totaldamage+=$row_xoops_weapons['damage'];
$total_rawdamage = $weapon_number*=$row_xoops_weapons['damage'];
?>
Now the closeing brackets for the for statements are actually included in html code below this statement, so they do close, if you are wondering.
This is the code that actually displays the calculations down at the bottom.
<table width="95%">
<tr>
<td>
<?php
if ($weapons_count > "1"){
echo "<td><input class=button type=submit value='Compare Weapon(s)'>";
}else{
echo "<td><input class=button type=submit value='Compare Weapon'>";
}
?>
<strong><font color="#FFFFFF" size="1">Total weapon damage: <?php
echo "$rawdamage Single Weapon Damage Points";
echo "| $total_rawdamage Multipal Weapon"; ?> Damage Points</font></strong></td>
</tr>
</table>
I hope that makes sense. Im learning this little by little, but this second array is throwing a kink in the chain. Tad confusing to me....:eek:
Thanks so much for your help
Tim