Displaying Sum() results to a webpage
Posted: Mon May 30, 2005 6:47 pm
Hi,
Please can somebody help me with my niggly issue please?
I want to display the SUM() value of a column and output it to a webpage.
I've been fiddling around with PHP for a week or two and have got my webpages to output rows and order those rows, using code as follows (relevant part): -
$result = mysql_db_query("interpre_music", "select * from Artist");
mysql_close();
?>
<?
while ($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
print("{$row['Rank']}");
echo "<br>";
}
?>
HOWEVER,
When I change the actual query line itself to: -
$result = mysql_db_query("interpre_music", "select Sum(Rank) from Artist");
I don't get a result, just good old - Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource.
Probably getting this error because I'm trying to put a single sum into a whole array, well I'm not sure.
Would someone have the modified code or an idea of how to display the SUM out onto a webpage?
Help Much Appreciated,
Bes.
Please can somebody help me with my niggly issue please?
I want to display the SUM() value of a column and output it to a webpage.
I've been fiddling around with PHP for a week or two and have got my webpages to output rows and order those rows, using code as follows (relevant part): -
$result = mysql_db_query("interpre_music", "select * from Artist");
mysql_close();
?>
<?
while ($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
print("{$row['Rank']}");
echo "<br>";
}
?>
HOWEVER,
When I change the actual query line itself to: -
$result = mysql_db_query("interpre_music", "select Sum(Rank) from Artist");
I don't get a result, just good old - Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource.
Probably getting this error because I'm trying to put a single sum into a whole array, well I'm not sure.
Would someone have the modified code or an idea of how to display the SUM out onto a webpage?
Help Much Appreciated,
Bes.