asbxzeeko
asbxzeeko

Reputation: 71

What is the issue with this function?

I created a function to recall the amount of posts in a certain category, in a forum. Here is the code for the function:

function num_posts_evedisc() {
    $sql3 = "SELECT COUNT(category) FROM forum_question WHERE category=3";
    $query3 = mysql_query($sql3);
    return($query3);
}

And this is the response I got, echo-ing it:

Resource id #14

(In my database, I have table forum_question and the column category. I tried replacing the (category) with (id) and that didn't work either.)

Thanks!

Upvotes: 0

Views: 43

Answers (2)

T.J. Crowder
T.J. Crowder

Reputation: 1074138

mysql_query returns a resource, which in turn gives you access to the result. To access the result, you have to use something to get information from the resource, such as:

if ($row = mysql_fetch_row($query3)) {
    return $row[0];
}

(You can also use other functions, like mysql_fetch_array or mysql_result.)

Note, though, that the mysql_* functions are deprecated and will be removed in a future version of PHP. Look at Mysql Improved Extension or PDO_MYSQL.

Upvotes: 3

dave
dave

Reputation: 64657

return mysql_result($query3, 0) 

is what you need to return

Upvotes: 1

Related Questions