I have this query:
select
problem_comments.user_id ,
problem_comment_id ,
problem_id ,
first_name ,
count(problem_comment_id) num
from problem_comments
left join users on problem_comments.user_id = users.user_id
where problem_id = 222
group by problem_comments.comment
and it is a basic join of a table where problems are listed and another table where comments for that problem are listed.
What I am trying to do with count(problem_comment_id) is see how many comments are in a problem so I can display that count. The problem with the current query is that it returns 3 rows because there are 3 comments for this problem. But in the column “num” it always lists 1.
How can I keep getting back the same data of problems and comments, but also get how many total comments there are?
Thanks!!
I see the php tag, so… You can use the
num_rowsfunctions after you execute the query.Here is some information if you are using
mysqli.And for
PDO.If you’re using the
mysqlextension (and shame on you, if so!), you can usemysql_num_rows()