tags:

views:

108

answers:

4

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  A: 

return mysql_num_rows($result) != 0;

Brendan Long
Thanks all for the input.
Patrick
I like the kind of questions where I can answer with one line of code :)
Brendan Long
+2  A: 
if (mysql_num_rows($result) == 0)
    return false
else 
    return true
Svetlozar Angelov
+1  A: 
return (bool) mysql_num_rows($result)
Deniss Kozlovs
A: 

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.

Carson Myers