Let me show u how I would do this:
/* grab results data from DB table, order by type and name ASC */
$get_catagories = "SELECT * from catagories ";
$get_catagories.= "ORDER BY catagory_type, catagory_name ASC";
$list_catagories = mysql_query($get_catagories)or die(mysql_error());
if (mysql_num_rows($list_catagories)) {
while ($row=mysql_fetch_assoc($list_catagories)) {
/**
* we dont make the output in here in case u need the array somewhere else
* creating the array based on your example:
* array (
* [0] => array (
* 'catagory_type' => 'listing',
* 'catagory_name' => 'bridal'
* )
* ...
* [23] => array (
* 'catagory_type' => 'other',
* 'catagory_name' => 'the main line scene',
* )
* )
*/
$catagories[] = $row;
}
}
/* print out the array so u should view how it looks like */
//echo "<pre>",print_r($catagories,1),"</pre>";
/* print out the output using <li> tags if $catagories is not empty */
if (!empty($catagories)) {
$tmp = '';
foreach ($catagories as $value) {
if (!empty($tmp) and $tmp!=$value['catagory_type']) {
echo "<li><!@@ EMPTY DUE TO NEW LISTING TYPE @@!></li>";
}
echo "<li>{$value['catagory_type']} => {$value['catagory_name']}</li>";
$tmp = $value['catagory_type'];
}
}
If u dont need that array and u need only that output, then this will do:
$get_catagories = "SELECT * from catagories ";
$get_catagories.= "ORDER BY catagory_type, catagory_name ASC";
$list_catagories = mysql_query($get_catagories)or die(mysql_error());
if (mysql_num_rows($list_catagories)) {
$tmp = '';
while ($row=mysql_fetch_assoc($list_catagories)) {
if (!empty($tmp) and $tmp!=$row['catagory_type']) {
echo "<li><!@@ EMPTY DUE TO NEW LISTING TYPE @@!></li>";
}
echo "<li>{$row['catagory_type']} => {$row['catagory_name']}</li>";
$tmp = $row['catagory_type'];
}
}