[eluser]Stilly[/eluser]
Hi
I am stuck in something which can be simply my ignorance of PHP and OOP, or of CI - But it's such an standard task, so I hope someone can point me in the right direction:
I have two tables - COMPANY and PRODUCT. Now I wanna make a search over Product or Company. The SQL would look like this:
Code:
SELECT *
FROM (`company`)
JOIN `product` ON `company`.`id` = `product`.`company_id`
WHERE UCASE(name) LIKE '%A%'
OR UCASE(brand) LIKE '%A%
I do this in my CI model with this code:
Code:
$this->db->select('*');
$this->db->join('product', 'company.id = product.company_id');
$this->db->like('UCASE(name)',strtoupper($search_string));
$this->db->or_like('UCASE(brand)',strtoupper($search_string));
$query = $this->db->get('company');
So far so good. Now I want to create an output in which I list every company and all of their products. So I process the search in the controller and call the view.
Code:
$search_string = $this->input->post('search_string');
$data['query']=$this->suche_model->getSearchResults($search_string);
In the view I have to foreach through the results -
but how?
a simple (not nestled) call
"<?php foreach ($query->result() as $row): ?>" gives me:
Code:
Company A, Product1
Company A, Product2
Company A, Product3
Company B, Product1
Company B, Product2
What I want to achive is:
Code:
Company A
* Product1
* Product2
* Product3
Company B
* Product1
* Product2
But I simply seem not to understand how to construct a nestled foreach here. Anyone a hint for me? (Or ist the whole approach crap and I should get the data in a multi-dimenional array?)
confused
Sven