I have a table in database:
id | int(25) Auto Increment
game | int(10)
user | int(9)
own | int(11)
userrate| int(2)
time | datetime
What I want now is to count rows with all the own types. I know it’s hard to understand, so I’ll post an example:
- own: 1; count: 5;
- own: 2; count: 3;
- own: 4; count: 10;
etc.
My initial thought was to create different queries for every own (since it’s only four of them), like this:
$this->db->where('user',$user);
$this->db->from('ownership');
$this->db->where('own','1');
$whole = $this->db->count_all_results();
return $whole;
But I think that’s not good at all. Can you suggest me the proper way?
I solved the problem. It’s similar to @vearutop’s solution, but it returns an array
own - count.Here’s the model: