views:

23

answers:

1

i have this function that brings me back a value by query a table in the database!

the code:

function recycle_check($recycle_id){

     $query = "SELECT recycle_id FROM notes WHERE user_id = '".$_SESSION['user_id']."' and recycle_id ='$recycle_id'";
           if(mysql_num_rows($query)== 0)
                return 0;
            else
                return 1;
}

but its giving me an error saying:

Warning: mysql_num_rows() expects parameter 1 to be resource

i just want the function to either give me a zero or a number 1!

0 for exists and 1 for deosnt exist!
+4  A: 

you need to run mysql_query before calling to mysql_num_rows

like :

$result = mysql_query("SELECT * FROM table1", $link);
$num_rows = mysql_num_rows($result);

what you need to pass to the function is:

The result resource that is being evaluated. This result comes from a call to mysql_query().

Haim Evgi