therocker Posted September 8, 2013 Share Posted September 8, 2013 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. 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 https://forums.phpfreaks.com/topic/281988-counting-number-of-columns-with-the-same-number/ Share on other sites More sharing options...
cataiin Posted September 8, 2013 Share Posted September 8, 2013 SELECT count, count(*) as forums_counting FROM forums_comment WHERE forums_id = '$forums_id' GROUP BY forums_id Link to comment https://forums.phpfreaks.com/topic/281988-counting-number-of-columns-with-the-same-number/#findComment-1448740 Share on other sites More sharing options...
Barand Posted September 8, 2013 Share Posted September 8, 2013 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 https://forums.phpfreaks.com/topic/281988-counting-number-of-columns-with-the-same-number/#findComment-1448754 Share on other sites More sharing options...
cataiin Posted September 8, 2013 Share Posted September 8, 2013 cataiin - where is column "count" coming from? I tried the code on localhost first time and I was wrong when I changed the values. Sorry! He just needs to modify the first count with forums_id in my code. Link to comment https://forums.phpfreaks.com/topic/281988-counting-number-of-columns-with-the-same-number/#findComment-1448755 Share on other sites More sharing options...
therocker Posted September 9, 2013 Author Share Posted September 9, 2013 Thanks guys. It's working now. How do I change this topic to Resolved? Link to comment https://forums.phpfreaks.com/topic/281988-counting-number-of-columns-with-the-same-number/#findComment-1448781 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.