开发者

php if condition

I can't find anything wrong with this... This should work right?

function ConfirmedNumber()
{
$rs = mysql_query("CALL ConfirmedNumber('" , $_SESSION['UserID'] . "',@Active)");
    while ($row = mysql_fetch_assoc($rs))
    {
        if ($row['Active'] = 1)
        {
        return true;
        }
    }
return false;
}

Assuming the Stored procedure returns a single row with the value '1' in it then I can call the function like this right?

if (ConfirmedNumber())
{
//do some stuff.开发者_开发知识库
}


To expand on my comment:

if ($row['Active'] = 1) should be if ($row['Active'] == 1) to work correctly.

If you want to avoid accidentally doing this in future, you could write your if statements like this:

if (1 == $row['Active'])

This way, you can't accidentally use = as PHP will throw a Fatal Error. You can read more about Comparison Operators at PHP.net


Comment below with the full answer:

The call to the stored proc... line $rs = mysql_query("CALL ConfirmedNumber('" . $_SESSION['UserID'] . "',@Active)"); had a comma instead of the period in the initial post.


you forgot your operator in your IF statement. Change it to this:

if ($row['Active'] == 1)

or even shorter

if ($row['Active'])


it can be something like this

    function ConfirmedNumber($id)
    {
    $rs = mysql_query("CALL ConfirmedNumber('" . $id . "',@Active)");
        while ($row = mysql_fetch_assoc($rs))
        {
            if ($row['Active'] == 1)
            {
            return true;
            }
        }
    return false;
    }
ConfirmedNumber($_SESSION['UserID']);
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜