Zharvek Posted May 6, 2006 Share Posted May 6, 2006 Well, I know how to count the number of rows a query returns, but Im looking for something a little more in depth and I can't figure it out, nor do I know exactly what to serach for.Here is what I'm trying to do, I hope somebody has done this before, or can help.Say I have a bunch of rows in a table, these are news posts by many users. I want to do a query that says how many posts each user has.My table looks like,ID | Username | Date | Data1 | Bob | Today | Testing2 | Bob | Today | Testing3 | Bob | Today | Testing4 | Bob | Today | Testing5 | Bob | Today | Testing6 | Tom | Today | Testing7 | Tom | Today | Testing8 | Tom | Today | TestingThats fake of course, but that is a good example. I want to say: Bob has 5 posts and Tom has 3. I can use a count of rows but that will return 8, and there are more users then those 2 and names cannot be hardcoded in, so a WHERE username= wont work.I hope somebody can help, thanks for looking! :-) Quote Link to comment https://forums.phpfreaks.com/topic/9165-count-rows-sort-of-problem/ Share on other sites More sharing options...
onepixel Posted May 6, 2006 Share Posted May 6, 2006 $query="Select ID, Username, Count(*) as Posts From Tablename Group By ID"; Quote Link to comment https://forums.phpfreaks.com/topic/9165-count-rows-sort-of-problem/#findComment-33778 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.