开发者

php mysql info retrieve

if ($cuser->loggedin()){
    if (!empty($_POST['returnto']))
    开发者_如何学Go{
        header("Location: ".htmlspecialchars($_POST['returnto']));
    }
    else
    {
        $query = ("SELECT id, username, check FROM users WHERE id=".$CURUSER['id']);
        $result = do_mysql_query($query);
        while($row = mysql_fetch_assoc($result))
{
    if ($row['check'] == true) {
        echo 'omg';
    } else {
echo 'omg false';


    }
    //To stop script executing next code ant print info...
    die();
}

    }

    die();
}

But always get: omg even if i chnage it to false. Any ideas ?


When you get results with mysql_fetch_assoc, the types of the values in the array will almost always be strings (they may occasionally be null, but that's not the problem here).

Any non-empty string will evaluate to true if you compare them with the == comparison operator.

The actual value being returned will not be true. It may be a string containing the word true or the word false. However, both of these will evaluate to true when compared to the boolean true.

Exactly what you should compare against depends upon what's in your database...


Your comment suggests that the field is an enum. This gives you two possible strings, "true" and "false". Since in PHP "false" == true is correct behaviour (because non-empty strings evaluate to true), you need to compare against a string value instead:

if ($row['check'] == "true") {


This is always TRUE in your case

if ($row['check'] == true) {...}

same as

if ($row['check']) {...}

Check for a $row['check'] value instead...

if ($row['check'] == 'true') {...} 

...if you have strings true and/or false as values of check column.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜