Jump to content

Counting number of columns with the same number


therocker

Recommended Posts

Hello, I can't seem to be able to count the number of rows that have the same numbers.
 
For example, in column forums_id, if the column contains 3 then count all of them with the number 3. If column contains then count all of them with the numbers 2. Here is what I mean.
 
count_rowsfw_zpsd4dc0170.png
 
Is there a way to do that? I've got something like this.

SELECT count(*) as forums_counting FROM forums_comment WHERE forums_id = '$forums_id' GROUP BY forums_id

cataiin - where is column "count" coming from?

 

therocker - exactly what problem are you having. Apart from the GROUP BY which is OK but unnecessary if you are selecting a single id it should work (so long as $forums_id contains a valid id. Try

SELECT forums_id,  count(*) as forums_counting 
FROM forums_comment  
GROUP BY forums_id

to get a count for each forum

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.