tjverge Posted February 8, 2011 Share Posted February 8, 2011 I'm not sure if this can be done, but I would like to get the sum for each $.row[''] result ex: if $row['robotics'] had values of 100,150,300 I would like to be able to show a total of 550 <?php echo "<Table border=1>"; echo "<tr><td></td><td>Robotics</td><td>Chiral Stuctors</td><td>Enriched Uranium</td><td>Mechanical Parts</td><td>Coolant</td><td>Consumer Electronics</td><td>Precious Metals</td><td>Reactive Metals</td><td>Oxygen</td><td>Toxic Metals</td></tr>"; $result = mysql_query("select * from `pi`"); while ($row = mysql_fetch_array($result)) { echo "<tr><td>".$row['pilot']."</td>"; echo "<td>".$row['robotics']."</td>"; echo "<td>".$row['chiralstuctors']."</td>"; echo "<td>".$row['enricheduranium']."</td>"; echo "<td>".$row['mechanicalparts']."</td>"; echo "<td>".$row['collant']."</td>"; echo "<td>".$row['consumerelectronics']."</td>"; echo "<td>".$row['preciousmetals']."</td>"; echo "<td>".$row['reactivemetals']."</td>"; echo "<td>".$row['oxygen']."</td>"; echo "<td>".$row['toxicmetals']."</td></tr>"; } echo "</table>"; ?> Quote Link to comment Share on other sites More sharing options...
requinix Posted February 8, 2011 Share Posted February 8, 2011 Try explode and array_sum. Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted February 8, 2011 Share Posted February 8, 2011 You should be able to just keep a running total in the while loop, if I understand you correctly. $result = mysql_query("select * from `pi`"); $total = 0; while ($row = mysql_fetch_array($result)) { echo "<tr><td>".$row['pilot']."</td>"; echo "<td>".$row['robotics']."</td>"; echo "<td>".$row['chiralstuctors']."</td>"; echo "<td>".$row['enricheduranium']."</td>"; echo "<td>".$row['mechanicalparts']."</td>"; echo "<td>".$row['collant']."</td>"; echo "<td>".$row['consumerelectronics']."</td>"; echo "<td>".$row['preciousmetals']."</td>"; echo "<td>".$row['reactivemetals']."</td>"; echo "<td>".$row['oxygen']."</td>"; echo "<td>".$row['toxicmetals']."</td></tr>"; $total += $row['robotics']; } echo "</table>"; Quote Link to comment Share on other sites More sharing options...
tjverge Posted February 8, 2011 Author Share Posted February 8, 2011 That looks like it will work thank you Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.