/ Published in: PHP

This will create a list grouped by the sorted field, which is an inner join on a category field.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
//connect to mysql and select db $query = 'SELECT c.category_name, p.* FROM tblProducts p INNER JOIN tblProductCategory c on p.prod_category = c.category_id;'; $currentCategory = null; $currentType = null; echo "<ul>"; if ($currentCategory != $row['category_name']) { if ($currentCategory !== null) { echo '</ul></li>'; } $currentType = null; } $currentCategory = $row['category_name']; $currentType = $row['prod_name']; } echo "</ul></li></ul>"; } ?>
Comments
