hey, you can join the two queries and make only one...

<?
function get_inventory()        
{
        $query = "SELECT c.cat_id, p.product_name FROM categories as c LEFT JOIN
products as p on (c.cat_id = p.cat_id)";
        $result = mysql_query( $query );
        if ( mysql_num_rows($query) > 0 )       
        {
                while ( $row = mysql_fetch_array($query, MYSQL_ASSOC) )
                {
                        $res_array[] = array('cat_id' => $row['cat_id'],
                                'product_name' => $row['product_name']
                                );
                }
                if (is_array($res_array)        
                {
                        return $res_array;
                }
                else    
                {
                        return 0;
                }
        }
        else    
        {
                return 0;
        }
}

//MAIN 
        
if (!$inventory = get_inventory());     
{       
        echo 'There is no result for your search.';
}
else
{
        $counter = count($inventory);
        for ($i=0; $i<$counter; $i++)   
        {
                print "<ul>\n";
                $current_inventory = $inventory[$i['cat_id']];
                $peek_inventory = $inventory[$i+1['cat_id']];
                if ($current_inventory != $peek_inventory)      
                {
                        print "<li>" . $current_inventory ."</li>";     
                        print "</ul>\n";
                        print "<ul>";
                        print "<li>" . $inventory[$i['product_name']] . "</li>";
                        print "</ul>\n";
                }
                else    
                {
                        print "<li>" . $inventory[$i['product_name']] . "</li>";
                }
                print "</ul>";
        }
}
?>

i think this work...didn't and couldn't test it...   hope it's not too
late....
KD

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to