View Full Version : Performing addition

09-12-2005, 04:52 AM
I'm not sure this ia a MySQL or PHP question?

I would like to add (math) some integers from MySql query. I don't know anything about this at all, but here goes...

I would like add another row in my php file that would sum up all the data that is being displayed. Here's my php code:






//Begin your table outside of the array
echo "<table border=0 bgcolor=ffff00 width=85%>\n";

$table_row = "<tr align=\"center\" valign=\"middle\">";
$table_row .= "<th><font size=\"4\"><font face=\"arial\"><u>Name</u></th>";
$table_row .= "<th><font size=\"4\"><font face=\"arial\"><u>Jugs Attended</u></th>";
$table_row .= "<th><font size=\"4\"><font face=\"arial\"><u>Favorite Beer</u></th>";
echo "$table_row\n";

// Request the text of all the names
$result = @mysql_query('SELECT name, previous_jugs_attended, favorite_beer FROM roster ORDER BY previous_jugs_attended desc limit 10');
if (!$result) {
die('<p>Error performing query: ' . mysql_error() . '</p>');

// Display the text of each name in a paragraph
while ( $row = mysql_fetch_array($result) ) {

$table_row = "<tr align=\"center\" valign=\"middle\">";
$table_row .= "<td WIDTH=25%><font size=\"4\"><font face=\"arial\">$row[name]</td>";
$table_row .= "<td WIDTH=15%><font size=\"4\"><font face=\"arial\">$row[previous_jugs_attended]</td>";
$table_row .= "<td WIDTH=15%><font size=\"4\"><font face=\"arial\">$row[favorite_beer]</td>";

echo "$table_row\n";