0

Hey guys,

I don't see anything wrong in the function but mysql_result is complaining about the parameter value passed to it.

function question_exists($question_id){

    $question_id = (int)$question_id;
    return ( mysql_result(mysql_query("SELECT COUNT('id') from `posts`  WHERE `id`=$question_id"),0) == 0) ? false : true;

    // if the question doesn't exist (equal to ZERO) then return false. Else, return true
}


    $id = '20';

    question_exists($id) =>  this gives me this message "Warning: mysql_result() expects parameter 1 to be resource, boolean given "

Thanks in advance for the help!

3
Contributors
6
Replies
7
Views
5 Years
Discussion Span
Last Post by rotten69
0

Disregard.... just DaniWeb changing the post above on me so it's already been done

Edited by GliderPilot

0

Sry for double post I took a look and it won't let me re-edit the above post.

You're getting that error because your query has failed. When it fails it returns FALSE hence the boolean error.

I would break your query down and add error handling to help identify the issue

$sql = "SELECT COUNT(`id`) FROM `posts`  WHERE `id`=$question_id";
$result = mysql_query($sql) or die (mysql_error());

Edited by GliderPilot

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.