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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.