anser316 Posted April 14, 2008 Share Posted April 14, 2008 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 More sharing options...
hitman6003 Posted April 14, 2008 Share Posted April 14, 2008 Change the column definition to be non-null and make the default value 0. Unless there's a good reason for it to be null? Link to comment https://forums.phpfreaks.com/topic/100971-solved-sum-if-0-put-value-0/#findComment-516382 Share on other sites More sharing options...
anser316 Posted April 14, 2008 Author Share Posted April 14, 2008 i had it as null, because i add data using php (sum) but i think now that if i have a default value of 0, then it can and should be not null. thanks Link to comment https://forums.phpfreaks.com/topic/100971-solved-sum-if-0-put-value-0/#findComment-516385 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.