computer training win98 win95 internet windows training consultant graphics webpage webpages.
I have seen many programmers wanting to select MySQL records that are many items in numerous categories (often using a JOIN on the category_id
Here is the solution to display all the itenms under each category title without having the category title repeated with every item:


 

 

 

This will save having to do multiple MySQL queries! optimize.

SELECT DISTINCT * FROM items JOIN categories ON items.cat = categories.cat_id

<?php
$prev_cat_id = 0; //initialize var
do {
if($result['cat'] != $prev_cat_id)
{
echo $result['cat_name']; }
echo "•".$result['item_name'];
$prev_cat_id = $result['cat'];
  } while ($result = mysql_fetch_assoc($result));
?>