开发者

mysql_fetch_row returns value above zero despite actually being zero

I'm running the following query but $new returns 0:

$count = mysql_query("SELECT COUNT(*) FROM flagged WHERE status=0") or die(mysql_error()); 
$new = mysql_fetch_row($count);

if ($new != 0) {
            echo "<script language=\"javascript\">$.titleAlert(\"New Logs - ($new[0])\");</script>";
        }

Problem is the if-condition keeps getting met when it shouldn't when $new != 0

I even tried:

if ($n开发者_高级运维ew > 0) {
//update title about new logs
}

Either way, the title is still updated and I'm not sure why.

New Logs - (0)


just do

var_dump($new);

and you'll see why your if doesn't work


Not sure what you mean. $new should be an array not a scalar value per the PHP documentation.

mysql_fetch_row documentation


this code

$new = mysql_fetch_row($count);

makes $new becomes an array

try to compare it like this:

if ($new[0] != 0)

or even better, so You would be 100% sure it's what You need.

if (count($new) == 1 && intval($new[0]) != 0)


mysql_fetch_row should return an array or FALSE.

Maybe adjust your conditional to:

if ( !$new ) {
    // some code here
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜