Jump to content

Edie

New Members
  • Posts

    1
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

Edie's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. I'm trying to make one big array with my websites menu that has the categorys and the products i'm using code i found at http://www.phpfreaks.com/forums/index.php?topic=326419.msg1536842#msg1536842 its working fine till i try get the sub category and its products into the array $cats = array( 0 => array( 'categoryID' => 1, 'name' => 'Menu', 'parent' => 0) ,1 => array( 'categoryID' => 50, 'name' => 'Takeaway', 'parent' => 60) ); //root of the category $categorys = array( 1 => array( 1 => array( 'categoryID' => 6 , 'name' => 'Breads' , 'parent' => 1 ) ,0 => array( 'categoryID' => 2 , 'name' => 'Drinks' , 'parent' => 1 ) ,2 => array( 'categoryID' => 7 , 'name' => 'Salads' , 'parent' => 1 ) ) ,2 => array( 0 => array( 'categoryID' => 4 , 'name' => 'Tea' , 'parent' => 2 ) ,1 => array( 'categoryID' => 18 , 'name' => 'Coffee' , 'parent' => 2 ) ) ); // the category themselfs $product = array(6 => array( 0 => array('productID' => 1, 'categoryID' => 6,'name' => 'Plain Bread', 'description' => 'description') ,1 => array('productID' => 2, 'categoryID' => 6, 'name' => 'Garlic Bread', 'description' => 'description') ) ,7 => array( 0 => array('productID' => 44, 'categoryID' => 7, 'name' => 'Garden Salad', 'description' => 'description') ,1 => array('productID' => 45, 'categoryID' => 7, 'name' => 'Greek Salad', 'description' => 'description') ) ,4 => array( 0 => array('productID' => 74, 'categoryID' => 4, 'name' => 'Green Tea', 'description' => 'description') ) ,18 => array( 0 => array('productID' => 75, 'categoryID' => 18, 'name' => 'Espresso', 'description' => 'description') ) ); // the products if(is_array($cats)) { foreach($cats as $cat) { if(is_array($categorys[$cat['categoryID']])) { foreach($categorys[$cat['categoryID']] as $category) { if(is_array($categorys[$category['categoryID']])) { foreach ($categorys[$category['categoryID']] as $subcat){ $subcat['product'] = $product[$subcat['categoryID']]; $subprod[] = $subcat; //have tryed using parent $subprod[$subcat['parent']] but it over rides it self each time } } $category['product'] = $product[$category['categoryID']]; $category['subcategory'] = $subprod; // here is where I'm having problem $this_category[] = $category; } } if(!empty($this_category)){ $ncategory[] = array($cat,$this_category); } $this_category = array(); } } print_r($ncategory); thank you for your time sorry for any spelling or grammar errors
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.