php:is_null和数据库结果

时间:2011-08-03 17:09:02

标签: php mysql null

我在捕获数据库结果时遇到问题,其值为null。我尝试了不同的角度(这都是在

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

环):

if(is_null($thisdept) == true) {
if(!is_numeric($thisdept) { 
if($thisdept == "" || $thisdept == NULL || $thisdept == "null" || $thisdept == "NULL") { 
没有运气。我甚至无法记录它:

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

甚至没有写入控制台(是的,firephp正确包含并且有效)。

这是db(mysql)中的条目 - 第19项,第3列

enter image description here

我确定这里有操作员错误,但我似乎无法弄清楚我做错了什么。任何帮助,将不胜感激。

更多代码:

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'];
                    }
                }
            }

1 个答案:

答案 0 :(得分:1)

$thisdept来自哪里? 您将MySQL结果提取到$row,而不是使用该数组!

检查变量是否为空,你可以用is_null()做到这一点,如果它是null,那就足够了,它会给出布尔值TRUE

另见:

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

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

编辑:

试试这个:

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

在这个if语句之后,尝试回显一些东西,看看代码是否到达那里 如果是这样,你的$username可能有问题吗?