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";} } Quote Link to comment 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? Quote Link to comment 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. Quote Link to comment 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; } ?> Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.