NotionCommotion
04-10-2006, 01:59 AM
I would like to perform a query sum of a table, and return 0 (i.e. zero) and not NULL if there is no matching data. The query that returns NULL (providing nothing matches) is:
SELECT SUM(my_column) AS temp_name FROM my_table WHERE id=1;
Don’t think if it matters, but I am using PHP to interface to MySQL, and am using the following code:
$sql="SELECT SUM(my_column) AS temp_name FROM my_table WHERE id=1";
$rs=mysql_query($sql, $conn);
$results=mysql_fetch_array($rs);
$total_my_column=$results[temp_name];
Any suggestions would be very appreciated.
Thank you very much!
SELECT SUM(my_column) AS temp_name FROM my_table WHERE id=1;
Don’t think if it matters, but I am using PHP to interface to MySQL, and am using the following code:
$sql="SELECT SUM(my_column) AS temp_name FROM my_table WHERE id=1";
$rs=mysql_query($sql, $conn);
$results=mysql_fetch_array($rs);
$total_my_column=$results[temp_name];
Any suggestions would be very appreciated.
Thank you very much!