Fearpig Posted November 5, 2007 Share Posted November 5, 2007 Hi Guys, Can someone have a quick look at my code for me.... I've written a page with some sales analysis on it and the figures are broken down in a table by month and customer. My problem is that when there are no sales in a particular month for that customer the cell of the table is blank as oppose to showing quantity = 0, value = £0 Code: $sql_month="SELECT * FROM qry_Sales_by_Customer WHERE Year = '$Year' AND Month = '$Month_by_Cust' AND Area = '$id' AND Account = '$Account'"; $result_month=odbc_exec($conn,$sql_month); if (!$result_month) {exit("Error in SQL");} while (odbc_fetch_row($result_month)) { $Price=odbc_result($result_month,"SumPrice"); $Price = number_format($Price); $Quantity=odbc_result($result_month,"SumQuantity"); $Quantity = number_format($Quantity); //Here is my attempt at entering 0, £0 instead of a null cell if (!isset($Quantity)){echo "0<br>£0";} elseif (is_null($Quantity)){echo "0<br>£0";} elseif (empty($Quantity)){echo "0<br>£0";} else {echo "$Quantity<br>£$Price";} } Link to comment https://forums.phpfreaks.com/topic/76059-replacing-null-values/ Share on other sites More sharing options...
trq Posted November 5, 2007 Share Posted November 5, 2007 Your code is pretty well impossible to read. What editor are you using? Link to comment https://forums.phpfreaks.com/topic/76059-replacing-null-values/#findComment-385019 Share on other sites More sharing options...
Fearpig Posted November 5, 2007 Author Share Posted November 5, 2007 Sorry... edited the code as it was just indented by miles! Should now be readable. Link to comment https://forums.phpfreaks.com/topic/76059-replacing-null-values/#findComment-385022 Share on other sites More sharing options...
farkewie Posted November 5, 2007 Share Posted November 5, 2007 Give this a go <?php $sql_month="SELECT * FROM qry_Sales_by_Customer WHERE Year = '$Year' AND Month = '$Month_by_Cust' AND Area = '$id' AND Account = '$Account'"; $result_month=odbc_exec($conn,$sql_month); if (!$result_month) {exit("Error in SQL");} $Price=odbc_result($result_month,"SumPrice"); $Price = number_format($Price); $Quantity=odbc_result($result_month,"SumQuantity"); $Quantity = number_format($Quantity); if (!isset($Quantity)) { $Quantity = "0<br>£0" } if ($Quantity ==''){ $Quantity = "0<br>£0"; } while (odbc_fetch_row($result_month)) { echo $Quantity; } ?> Link to comment https://forums.phpfreaks.com/topic/76059-replacing-null-values/#findComment-385025 Share on other sites More sharing options...
Fearpig Posted November 5, 2007 Author Share Posted November 5, 2007 Cheers farkewie, but it still isn't displaying anything if there are no records. Link to comment https://forums.phpfreaks.com/topic/76059-replacing-null-values/#findComment-385070 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.