Jump to content

Replacing NULL Values


Fearpig

Recommended Posts

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

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