I have a MySQL query like this:
SELECT c.id
, c.company_name
, b.brand_id
, b.brand_name
FROM companies as c
JOIN brands AS b
ON c.id = b.company_id;
which returns a table like this:
The results are stored in $items
I want to be able to use a foreach loop to display the results like this:
<ul>
<li><b>adidas plc</b></li>
<li>adidas</li>
</ul>
<ul>
<li><b>coca-cola</b></li>
<li>coke</li>
<li>dr pepper</li>
<li>7up</li>
</ul>
<ul>
<li><b>ebay</b></li>
<li>Duobam</li>
</ul>
How can I accomplish this with just using the above join query? I can do it by first querying the company table and then doing a new query for each on the brand table but with thousands of companies and multiple brands for each its going to cause too many queries.
foreach($items as $item){
echo '
<ul>
<li><b>'.$item['company_name'].'</b></li>
<li>'.$item['brand_name'].'</li>
</ul>
';
}

<ul>