1

I'm having a problem trapping a database result where the value is null. I've tried different angles from (this is all in the

while($row = mysql_fetch_array($results)){

loop):

if(is_null($thisdept) == true) {
if(!is_numeric($thisdept) { 
if($thisdept == "" || $thisdept == NULL || $thisdept == "null" || $thisdept == "NULL") { 

no luck. I can't even seem to log it:

$isNull = is_null($thisdept);
$firephp->fb($isNull . "::" . $thisid);

doesn't even write to the console (yes, firephp is included correctly and works).

Here's the entry in the db (mysql) - item 19, column 3

enter image description here

I'm sure there's operator error going on here but I just can't seem to figure out what I am doing wrong. Any help would be appreciated.

More code:

if ($itemcount > 0) {

        while($row = mysql_fetch_array($results)){

            //clean up data
            $thisid = $row['id'];
            $thisdate = $row['theDate'];
            $thisdept = $row['department'];
            $thisbucket = $row['bucket'];
            $thispub = $row['publication'];
            $thisarea = $row['area'];
            $thishours = $row['hours'];
            $thisdesc = $row['description'];
            $thistimestamp = $row['theTimestamp'];
            $thissortdate = $row['sortdate'];
            $workDate = $row['workDate'];


            $isNull = is_null($thisdept);
            $firephp->fb($isNull . "::" . $thisid);
            //if department == null then we should just select the user's department and they can fix it on an edit
            //$thisdept == "" || $thisdept == "null" || $thisdept == "NULL" || $thisdept == null || $thisdept = "Null"
            if (is_null($thisdept) == true) {

                $udQuery = "SELECT department FROM users WHERE username = '" . $username . "'"; 
                $udResults = $db->getResults($udQuery);
                $udItemCount = count($udResults); 
                if ($udItemCount > 0) { 
                    while ($udRow = mysql_fetch_array($udResults)) { 
                        $thisdept = $udRow['department'];
                    }
                }
            }
5
  • 1
    Some weird logic here: if(is_null($thisdept) == true) { if(!is_numeric()... If it's NULL then it's obviously not numeric. Commented Aug 3, 2011 at 17:13
  • Was the above meant to be if (!is_null($thisdept))? Commented Aug 3, 2011 at 17:14
  • @Michael: those were the 'different angles' the OP tried AFAIK. Commented Aug 3, 2011 at 17:16
  • @Pruitlgoe: we need more code, because we cannot see how $thisdept is set... Commented Aug 3, 2011 at 17:18
  • @Michael - I wasn't using them all at the same time - sorry for that confusion : D Commented Aug 3, 2011 at 17:20

1 Answer 1

1

Where does $thisdept come from? You are fetching the MySQL result to $row, than you have also to use that array!

Checking if the variable is null, you can do that with is_null(), that's sufficient, if it is null, than it will give the boolean TRUE.

See also:

http://www.php.net/manual/en/language.types.null.php

http://www.php.net/manual/en/function.is-null.php

EDIT:

Try this:

if (is_null($thisdept) == true) {

after this if statement, try to echo something to look if the code reaches till there if so, maybe there is something wrong with your $username?

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.