Hi,
I am trying to create a function which will be able to fetch record from the database but the problem is the data is to be arrange in tree form. Means I to arrange my categories like below:
1) Computers
-----2)Laptops
-----3)Keyboards
4) Mobiles
-----5)Samsung
-----6)Sony
Now assume the bullet numbering of these categories as their id in database and parent id of 1 and 4 number is null but of 2, 3, 5 and 6 as their above.
Function I am using is below:
function CategoryForListItem($parent_id = "") {
$sql = empty($parent_id) ? "SELECT cat_id, cat_name, cat_level FROM category WHERE cat_parent_id IS NULL" : "SELECT cat_id, cat_name, cat_level FROM category WHERE cat_parent_id='$parent_id'";
$result = mysql_query($sql);
while($row = mysql_fetch_array($result)) {
$category_list_array[] = array($row['cat_name'],$row['cat_id']);
CategoryForListItem($row['cat_id']); //calling same function
}
return $category_list_array;
}
This Function Returns: It only returns the values from first while loop that is only return two loops, first is array("Computers", 1) and second is array("Mobiles", 4) . Like this
array(
array("Computers",1),
array("Mobiles", 4)
)
My Aim To Get: I want an array from this function and array is multidimensional array with all categories values with their id as given below:
array(
array("Computers",1),
array("Laptops",2),
array("Keyboards",3),
and so on arrays...
)
Thanks in Advance.
Please help me as it is urgent.