0

Im trying to get the function below to return TRUE if it finds a matching row, and FALSE if it finds 0 rows.

function IsOpenEvent($id) {
    $result = mysql_query("SELECT * FROM `events`
                             WHERE `access` = 'public'
                               AND `id` = '$id'
                             LIMIT 1")
                or die(mysql_error());
    if ($result) {
        return TRUE;
    } else {
        return FALSE;
    }
}

4 Answers 4

4

return mysql_num_rows($result) != 0;

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

1 Comment

I like the kind of questions where I can answer with one line of code :)
2
if (mysql_num_rows($result) == 0)
    return false
else 
    return true

Comments

2
return (bool) mysql_num_rows($result)

Comments

0

just to let you know, you should really be calling mysql_real_escape_string() on $id, otherwise you're leaving an SQL injection vulnerability in your code.

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.