Hi i’m trying to count tables where a specific row is more than 0.
if table(requests) have a row(rq_stamp) that is more than 0 it should be counted / selected.
This is what i got so far but i always get 1. ($num_rows is always 1).
$rq_notice = mysql_query("SELECT * FROM requests WHERE rq_poster = '$rq_notice_user' HAVING COUNT(rq_stamp) > 0 ") or die(mysql_error());
if(mysql_num_rows($rq_notice) > 0 )
{
$num_rows = mysql_num_rows($rq_notice);
echo $num_rows;
}
Thanks for any help that can be provided, i’m sorry if the question has been answered before but i could not find it when i searched.
I think you do misunderstand what count does 😉
What you’re writing here is a query. In other words, you’re sending someone searching for data. What you will get is just what you defined in the SELECT part.
Count is a function that you can use if you group by a specific column. You can here f.e. set a query on a table where you store photos and their uploaders. Using count you can now get a number of uploaded photos per uploader. More examples: http://dev.mysql.com/doc/refman/5.1/en/counting-rows.html
I think you want to do something like this:
Just get all requests where the poster is X and the timestamp is > 0. And using PHP you can now check how much rows got collected and you can get the rows by using mysql_query. http://php.net/mysql_query
But please use mysqli or PDO instead of mysql. I’m here just talking about the functions you use in PHP. The PHP-extension mysql is deprecated since PHP 5.5 and you shouldn’t use something, you now know of, will be removed. If you ask, why it is deprecated: https://www.php.net/manual/en/faq.databases.php#faq.databases.mysql.deprecated