How to display products under category [ data grouping ]
<p>I am new to php-mysql. Can somebody help on the issue below? If so, please explain a bit so that I can learn. Thanks in advance.</p>

<pre><code>$data=mysql_query("SELECT tbl_category.*, tbl_product.* FROM tbl_category LEFT JOIN tbl_product ON tbl_category.cat_id=tbl_product.cat_id ORDER BY tbl_category.cat_id");
$color="1";
while($fetch=mysql_fetch_array($data, MYSQL_ASSOC)){ 

if($fetch['cat_name'] != $category){  //this returns error: "Notice: Undefined variable: category in /.../filename.php on line [this line number]
    $catdes = $fetch['pd_description'];
    echo "&lt;tr bgcolor='#A9F5F2'&gt;&lt;td colspan=\"2\"&gt;&lt;div align=\"center\"&gt;&lt;br/&gt;&lt;b&gt;". $fetch['cat_name']."&lt;/b&gt;&lt;br /&gt;&lt;span class=\"itemdescription\"&gt;". $catdes."&lt;/div&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;";
    $category = $fetch['cat_name'];
}

    $item = $fetch['pd_name']; 
    $desc = $fetch['pd_description'];
    $price = $fetch['pd_price'];
    if($color==1){
        echo "&lt;tr bgcolor='#FFFFFF'&gt;";
        echo "&lt;td width=\"93%\"&gt;&lt;div align=\"left\"&gt;";
        echo $item . "&lt;br /&gt;&lt;span class=\"itemdescription\"&gt;";
        echo $desc ;
        echo "&lt;/div&gt;&lt;/td&gt;&lt;td width=\"7%\" VALIGN=\"top\" ALIGN=\"right\"&gt;&lt;div align=\"right\"&gt;"; 
        echo $price ."&lt;/div&gt;&lt;/td&gt;&lt;tr&gt;";
    $color="2";
    }
    else{
        echo "&lt;tr bgcolor='#F2F2F2'&gt;";
        echo "&lt;td width=\"93%\"&gt;&lt;div align=\"left\"&gt;";
        echo $item . "&lt;br /&gt;&lt;span class=\"itemdescription\"&gt;";
        echo $desc ;
        echo "&lt;/div&gt;&lt;/td&gt;&lt;td width=\"7%\" VALIGN=\"top\" ALIGN=\"right\"&gt;&lt;div align=\"right\"&gt;"; 
        echo $price ."&lt;/div&gt;&lt;/td&gt;&lt;tr&gt;";
    $color="1";
    }
}
</code></pre>
