Tuesday, July 5, 2011

Listing subcategories or chilld categories using php

We can use the following function for getting the subcategories up to any level. It is using recursive technique.

function getSubCats($catid){
        $query= "select cat_id from category where cat_parent_id='$catid'";
        $rst =  $this->db->query($query);
            return null;
            foreach($rst->rows as $row) {
                $categories[] = $row['cat_id'];
                $children = $this->getSubCats($row['cat_id']);   
                    foreach($children as $child){
                        $categories[] = $child;   
            return $categories;


No comments:

Post a Comment