[eluser]codex[/eluser]
[quote author="llbbl" date="1194591988"]Yea sorta .. but who cares if your not using a view file, like if you are waiting for the designer to finish the HTML template. Something like this I do before I hassle with a view file to make sure I am getting the right data, to make sure that my php is working how I want it.
Here is same example except assuming you are going to use a view file.
Code:
$sql = $this->db->query("SELECT * FROM `people` ORDER by peopleid ASC ");
if($sql->num_rows()>0){
foreach($sql->result() as $row){
$query = $this->db->query("SELECT * FROM `address` WHERE peopleid='$row->peopleid' ORDER by addressid ASC ");
if($query->num_rows()>0){
foreach($query->result() as $obj){
$address[]= "<div>$row->firstname, $obj->address</div><br />";
}
}
}
}
$data['address'] = $address;
$this->load->view('whatever', $data);
Edited it again to make little more sense.
edited again .. forgot the equals ><[/quote]
I'm with you so far. But the trick is not to output the result of one query, but of two, like so:
Code:
output loop 1: category name 1
output loop 2: category item 1 (belongs to category name 1)
category item 2 (belongs to category name 1)
category item 3 (belongs to category name 1)
output loop 1: category name 2
output loop 2: category item 1 (belongs to category name 2)
category item 2 (belongs to category name 2)
category item 3 (belongs to category name 2)
output loop 1: category name 3
output loop 2: category item 1 (belongs to category name 3)
category item 2 (belongs to category name 3)
category item 3 (belongs to category name 3)
This seems impossible to do in a controller and output it to the view. I wonder how the rest of you is doing this. I bet there's plenty of instances where you (=other CI users) need to do the same.