0

How can I sort my database results into something like this using PHP. Basically, I am trying to group the results, and then count the results found in the database.

  • Starcraft (1)

  • League of Legends (4)

  • Minecraft (2)

  • Call of Duty: Black Ops (1)

I know there is a way, but I can't figure out the logic for this situation. If someone can give me an insight, that would be nice. Thank you!

Here is my SQL Table:

enter image description here

Community
  • 1
  • 1
Luigi R.
  • 229
  • 4
  • 20

1 Answers1

2

Looks like a straightforward count and group by statement:

select
    game,
    count(*)
from
    yourTable
group by
    game

Based on this question, you should really take a read of this question and answer I wrote for situations like this as it explains in a lot of detail what is going on and how to get the results you want.

Community
  • 1
  • 1
Fluffeh
  • 33,228
  • 16
  • 67
  • 80