Welcome Guest, Not a member yet? Register   Sign In
Categories and Subcategories ISSUE
#1

[eluser]Unknown[/eluser]
I am trying to make a restaurant menu and I have to have **Categories** and **Subcategories**, so I created the following tables:

Table: Categories
ID
NAME

Table: Subcategories
ID
NAME
PRICE
DESCRIPTION
CATEGORIES_ID

I am using DataMapper and the problem I having with the code below is that the result of the FOREACH LOOPS I am getting is that only the LAST Subcategory is showing, where there are few more entries.

So I have 2 entries each in the tables for SubCategories and the result of the code is giving me this:

Quote:ALCOHOL -> VODKA
NONALCOHOL -> FANTA

and it needs to be
Quote:ALCOHOL -> VODKA, AFTERSHOCK,
NONALCOHOL -> FANTA, SPRITE


Code:
public function index()
    {

   $categories = new Category_model();
   $subcategories = new Subcategory_model();
   $categories->get();
   $subcategories->get();

   $recent_categories = array();
   foreach ($categories as $category)
   {
     foreach($subcategories as $subcategory)
     {
      if($subcategory->categories_id == $category->id)
      {
         $single_category = array
         (
       'category_name' => $category->name,
        'subcategory_name' => $subcategory->name,
        'subcategory_description' => $subcategory->description,
        'subcategory_price' => $subcategory->price,
         );
       }
     }
     array_push($recent_categories, $single_category);
   }

   $data = array
   (
     'categories' => $recent_categories,
   );

    $this->parser->parse('templates/content_menu', $data);
    }



THIS IS THE VIEW:

Code:
{categories}
      <div class="grid-12 ourmenu">
        &lt;!-- MENU TITLE --&gt;
        <h2>{category_name}</h2>
        <hr/>
          &lt;!-- MENU ITEM --&gt;
          <h4>
            <a class="clb-photo" href="&lt;?php echo site_url('design/images/photos/food.jpg'); ?&gt;">
              {subcategory_name}
            </a>
            <span>{subcategory_price}</span>
          </h4>
          <p>{subcategory_description}</p>
      </div>
      {/categories}
#2

[eluser]www.sblog.in[/eluser]
You can get an idea http://www.webtuts.in/infinite-dynamic-m...and-mysql/




Theme © iAndrew 2016 - Forum software by © MyBB