Welcome Guest, Not a member yet? Register   Sign In
mysql header and sub-rows
#1

[eluser]limit[/eluser]
I am hoping someone can shed some light on how I can do the following. I found some examples on the web which seem to use mysql_assoc, but how I do this with CI I am lost.

Basically, lets say I have 3 mysql columns. (id, Name, Category)

I want to be able to list all names under their defined category. If I do GROUP BY category it outputs only 1 result, however I need it to output like below.

Example:

Category 1
Name1
Name2
Name3

Category 2
Name4
Name5
Name6

my code is something like this:

Code:
$query = $this->db->query("select * from data where id IN (" . $id_array . ")");
if ($query->num_rows() > 0) {
foreach ($query->result() as $row) {
echo $row->category; // This should group all categorys into one single category
echo $row->name; // These should output under the category they are assigned.
/*
Example output should be like
Category 1
Name1
Name2
Name3

Category 2
Name4
Name5
Name6
*/
}
}

Any help would be appreciated.




Theme © iAndrew 2016 - Forum software by © MyBB