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
https://forums.phpfreaks.com/topic/76059-replacing-null-values/
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
https://forums.phpfreaks.com/topic/76059-replacing-null-values/#findComment-385025
Share on other sites

Archived

This topic is now archived and is closed to further replies.

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