• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to group product by category?

#1
Wink 
I've a project where i've to show content by group, now i not only have to group them and show total, i've to group them and show all content inside it. My Table looks like this

-----------------------------------------------------------------
   id    |    name       |         role         |         salary
-----------------------------------------------------------------
   1     |      abc        |       dev           |          5k
   2     |      xyz        |       sr. dev      |         7k
   3     |      jkm        |       intern        |         1k
   4     |      asf         |       dev           |         5k
   5     |      asdf       |       mang.       |        10k
   6     |      vas        |       intern        |         1k
   7     |      m.kj       |       dev           |         5k
   8     |      kjnm      |       dev           |         5k
   9     |      knlk       |       sr. dev      |         7k
 10     |      kljf         |       dev           |         5k
Reply

#2
The CodeIgniter Active Record Class offers a method called group_by which you can use to query a table with the results representing a grouping of the records in the table.
Code:
$this->db->select("COUNT(id)");
$this->db->group_by("role");
$this->db->get("my_table");

You should probably read the mysql documentation on 'group by'. Or if you are using some other DBMS, check out its documentation on group by.
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.