Friday, October 14, 2011

category sub category program


mysql_connect("localhost","root","");
mysql_select_db("test");
class Categories
{
public function categories_tree($country_id='',$parent='0',$spacer='')
{
$sql = mysql_query("SELECT * FROM categories WHERE parent='$parent'");
$num = mysql_num_rows($sql);
$spacer .= '- ';
while ($row = mysql_fetch_array($sql))
{
if ($num == 0 || $row['parent']=='0')
{
$spacer = '';
}
echo $spacer.'‘.$row['name'].’
‘;
$this->categories_tree($country_id, $row['id'], $spacer);
}
}
}
$cat = new Categories();
$a = ”;
echo $cat->categories_tree(0, $a);
?>

1 comment: