Jump to content

Counting number of columns with the same number


therocker
Go to solution Solved by Barand,

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
Link to comment
Share on other sites

  • Solution

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.