Jump to content

[SOLVED] SUM- if 0, put value 0


anser316

Recommended Posts

If there is no data in x.stock, how do i put the value '0' in total_stock. I get a blank as it has NULL.

If it helps, total_stock is float, and stock is int

 

$result2 =mysql_query("UPDATE branch_items i

SET i.total_stock=(SELECT SUM(x.stock)

from stock_expdates x

WHERE x.drug_id=$drug

AND i.drug_id=x.drug_id)

WHERE i.drug_id=$drug")

 

$result3 =mysql_query("SELECT total_stock from branch_items

WHERE drug_id=$drug")or die ("Query:<br>$result3<br>Error:<br>".mysql_error());;

$row = mysql_fetch_array( $result3 );

echo $row[total_stock];

 

 

Link to comment
https://forums.phpfreaks.com/topic/100971-solved-sum-if-0-put-value-0/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.