在activerecord codeigniter中分组

I'm using activerecord in codeigniter. I have a DB that looks like this:

+------------+--------------|----------+
|clientName  | websiteNumber|langNumber|
|------------|--------------|----------|
|john        | 1            | 2,5      |
|john        | 2            | 2,3      |
|mark        | 1            | 15,5     |
|steve       | 1            | 5        |
|steve       | 2            | 5        |
|amy         | 1            | 15       |
+------------+--------------+----------+

I want to group by clientName, then by websiteNumber, so that the view looks something like this:

  john
    websiteNumber 1 langNumber 2,5
    websiteNumber 2 langNumber 2,3
  mark
    websiteNumber 1 langNumber 15,5
  steve
    websiteNumber 1 langNumber 5
    websiteNumber 2 langNumber 5
  amy
    websiteNumber 1 langNumber 15

I'm not worried about the HTML or how to parse through the result. I want to know the best way to use one query using active record to get it to return an array that I can then loop through in the view.

I thought of a couple of hacky ways - like querying in a foreach loop, but it felt wrong and I hope that there is a better way.

You need to use the order_by method:

$this->db->order_by('clientName', 'asc');
$this->db->order_by('websiteNumber', 'asc');

$query = $this->db->get('client');

return $query->result_row();

I'm not an active records expert, but I guess you should just use a group by on client name then group_concat combined with php explode for the view.

My experience with active records is that you should just expect the same output as mysql_fetch_assoc. It's not as mature as Doctrine