I'm using the following code to display the categories available in my shop. It works fine, except when I modify a product, I want it to print "selected" in the <option> where the category is previous used. As it is now, it defaults back to the category root, and I have to reselect the correct category or else it saves as the root.

Any help would be greatly appreciated:

<?php
require_once 'library/config.php';
require_once 'library/category-functions.php';
require_once 'library/product-functions.php';
require_once 'library/cart-functions.php';

$_SESSION['shop_return_url'] = $_SERVER['REQUEST_URI'];

$catId  = (isset($_GET['c']) && $_GET['c'] != '1') ? $_GET['c'] : 0;
$pdId   = (isset($_GET['p']) && $_GET['p'] != '') ? $_GET['p'] : 0;

require_once 'include/header.php';

function traverse($root, $depth, $sql) 
{ 
     $row=0; 
     while ($acat = mysql_fetch_array($sql)) 
     { 
          if ($acat['cat_parent_id'] == $root) 
          { 
               print "<option value='" . $acat['cat_id'] . "'>"; 
               $j=0; 
               while ($j<$depth) 
               {    
print "&nbsp;&nbsp;"; $j++; } if($depth>0) { print "-"; } print $acat['cat_name'] . "</option>\n"; mysql_data_seek($sql,0); traverse($acat['cat_id'], $depth+1,$sql); } $row++; @mysql_data_seek($sql,$row); } } print "<select name='cboCategory' id='cboCategory' class='box'>"; $selcat="SELECT * from tbl_category order by cat_name ASC"; $selcat2=mysql_query($selcat) or die("Could not select category"); traverse(0,0,$selcat2); print "</select>"; ?>
    Write a Reply...