Php and MYSQL nulls

I’d like to be able to treat 0 flow measurements differently than NULL flow measurement values. If the flow is null, that means that the flow was too high to measure and I want to set it to a “no value” value with phpchartdir.NoValue. However, I can’t seem to figure out how to find only the nulls. This code finds both nulls and 0 values in the loop.

$SQLstatement = ‘Select DATE, QD From Flow
WHERE DATE > unix_timestamp(“2006-04-13”) and DATE < unix_timestamp(“2006-07-31”)
and SITE = "RBDW"
order by DATE’;

#Read in the data into arrays

@ $db = new mysqli ( “xxx”, “xxxxx”, “xxxxx”, ‘xxx’);
if (mysqli_connect_error())
echo ‘Error: Could not connect to database.’;
$result = mysqli_query($db, $SQLstatement);

$num_results = $result->num_rows;

$count = 0;
while ($row = mysqli_fetch_row ($result)) {
$dateQD[$count] = $row[0];
$QD[$count] = $row[1];
if ($QD[$count] == 0) {
$QD[$count] = NoValue;

This signature line intentionally blank.

use === instead of ==, as the former also compares types. 0 == null is true, but 0 === null is false.

Wow, that was easy, but so hard to find in the index my PHP book! So the sytax for testing if $QD === null that seems to work for me is just “if ($QD[$count] === null) {” Those are the records I want to set to NoValue.

OK, then how can I change this script that inserts records into MySQL so that when it finds a river flow value that is coded “MISSING” on the url screen scrape, a “NULL” gets inserted into $nQDVAL in the MySQL table?

for ($i=3; $i<count($aContents)-1; $i ) {

// Dates are formatted as 10 characters
$cDateStr = substr($aContents[$i],0,10);
#convert date string (a date in human language) to a date in programming language
$myDates = strtotime($cDateStr);

// QD is everything in the trimmed value after the last space
$nQDVal = substr($aContents[$i], strrpos(trim($aContents[$i]), chr(32)) 1);
$query = “insert into Flow values (’”.$myDates."’, ‘".$nQDVal."’, ‘".RBDW."’)";
$result = $db->query($query);

This signature line intentionally blank.

in an insert query, you can use null as a value if you don’t put quotes around it. so when you have “MISSING”, build this query instead:

$query = “insert into Flow values (’”.$myDates."’, null, ‘".RBDW."’)";