<?php
print "<select name='catId' class='required'>";
print "<option value=''>Select Category</option>";
$selcat = "SELECT * from category order by name ASC";
$selcat2 = mysql_query($selcat) or die("Could not select category");
traverse(0, 0, $selcat2);
print "</select><br>";
function traverse($root, $depth, $sql) {
$row=0;
while ($acat = mysql_fetch_array($sql)) {
if ($acat['parentID'] == $root) {
print "<option value='" . $acat['id'] . "'>";
$j=0;
while ($j<$depth) {
print " ";
$j++;
}
if($depth>0){
print ">> ";
}
print $acat['name'] . "</option>";
mysql_data_seek($sql,0);
traverse($acat['id'], $depth+1,$sql);
}
$row++;
mysql_data_seek($sql,$row);
}
}
?>
|