How to calculate the same lines in the comments table?

+---+------------+-------------+ | | user | comment | +---+------------+-------------+ | 1 | ed | comment1 | | 2 | ed | comment2 | | 3 | edn | comment3 | | 4 | dima | comment1 | +---+------------+-------------+ 

php should display the number 3, if I want to count the number of lines with the value ed . How can I do it?

The current request is:

 $cout_user = mysqli_query($this->db, "SELECT id, user, COUNT(*) FROM comments GROUP BY user"); 

And how to implement the output of the number of rows counted?

  • one
    so that there are no problems with the output, it is more correct to write COUNT(*) as count - Alex
  • 3
    and why do you need to display extra columns? $cout_user = mysqli_query($this->db, "SELECT id FROM comments WHERE user = 'ed'"); echo mysqli_num_rows($cout_user); - Alex
  • Thank you so much, buddy! - FLWRZ4U
  • one
    You can simply put upvote on the comments (daw to the left of the comment when you hover on the comment) :) - Alex
  • @Alex is more правильнее писать COUNT(*) as count - and maybe even COUNT(1) as count ? - Alexey Shimansky

2 answers 2

 SELECT id, user, COUNT(*) FROM comments WHERE user = ed 
  • Tell me, please, how to get the quantity. The request is made, and the conclusion is how to implement? - FLWRZ4U
  • $ row_cnt = mysqli_num_rows ($ cout_user); - Solo_777
  • @ user207012 to learn the programming language base, for example, for a start - Alexey Shimansky
  • The answer is wrong even in terms of sql syntax. Not enough quotes. - AK
 $cout_user = mysqli_query($this->db, "SELECT id FROM comments WHERE user = 'ed'"); echo mysqli_num_rows($cout_user); 
  • one
    Please mark your answer as accepted as a decision (the green daw below the digit to the left of the answer text). This will mean that you have received an answer to your question and this answer is the most suitable solution for you. - Alex