0

I am running this query:

mysql_query("SELECT * FROM $pid WHERE ff IS NOT NULL ORDER BY time_out");

I am getting a response with some rows that are null in the ff column.

I verified this later on in the code with:

if ($reps[$i]['ff'] == null)
    {
    $test = "ff is null";
    } 
else 
    {
    $test = $reps[$i]['ff'];
    } 

Not sure what I am missing here. Thanks in advance.

  • Maybe empty string treated as NULL – Lukasz Szozda Aug 25 '18 at 09:21
  • maybe, but is why I tried to test for that with "if ($reps[$i]['ff'] == null)" would that not work? – Cory Blair Aug 25 '18 at 09:24
  • Mapping. Your query may return `''` but PHP treats it as NULL. I am not expert of PHP that is why only educated guess. – Lukasz Szozda Aug 25 '18 at 09:25
  • If you `print` or `var_dump` your `$reps[$i]['ff']`, what does it contain? PHP's `null` and SQL's `NULL` are two different things. Your check for `null` in PHP is checking to see if that array element is defined at all. It is. But what does that element contain? – David Aug 25 '18 at 09:27
  • Ah yes, I see what you saying. tried: if ($reps[$i]['ff'] == "") and that did return true. – Cory Blair Aug 25 '18 at 09:28
  • `"" == null` evaluates to `true` because it juggles types. If you really want to check for `null` use: `$reps[$i]['ff'] === null`. See https://stackoverflow.com/a/80649/7362396 – Tobias K. Aug 25 '18 at 09:28
  • === null returned false. so must be an empty string then. thanks, guys. when i insert the row the ff value is from $ff = tax_test(); tax_test should be returning "return null;" does that sound ok? – Cory Blair Aug 25 '18 at 09:35

1 Answers1

1

Use query

mysql_query("SELECT * FROM $pid WHERE ff IS NOT NULL and $pid != '' ORDER BY time_out");