Welcome Guest, Not a member yet? Register   Sign In
Returning several arrays to a view
#1

[eluser]dwlamb[/eluser]
I have an application written from scratch that I wish to convert for learning to use Codeigniter. I am having a challenge with determining how to retrieve an array of data and format in html output required to display a tree navigation system powered by jQuery.

This application is a cookbook. In my database a typical record is as follows by column name and brief description:

id - incremental number; this ill be used as a variable later on for extracting one recipe to display in the browser
category - text of recipe category (e.g., Main Dish, Dessert, etc.)
recipe - the name of the recipe (e.g., Apple Pie)

... more fields but these are the ones I need to focus on right now.

The end result of the HTML has to appear as below in order for jQuery to work:
Code:
<ul id="navigation">
    <li>Dessert
      <ul>
        <li>Apple Crisp</li>
        <li>Blueberry Sauce</li>
        <li>Butter Tarts</li>
        <li>Carrot Cake</li>
        <li>Sponge Custard</li>
        <li>Sweet Mince Meat</li>
      </ul>
    </li>
    <li>Sauces & Condiments
      <ul>
        <li>Bar B Que Sauce</li>
        <li>Hollandaise Sauce</li>
        <li>Picalilli</li>
      </ul>
    </li>
  </ul>

I know how I would do this in a conventional PHP application for it works for me already. But I need to figure out how to do it in a controller or model under CI. This is the logic as I see it:

1. Query for a unique list of recipe categories
2. output it to an array, result_categories
3. For each of those categories, query the database for the recipes in each category
4. output it to an array, result_catgory_dessert, result_catgory_maindish,.... etc
5. return each of the arrays to the view for processing into HTML

I'm stumped about how to do it with CI. Input would be greatly appreciated.


Messages In This Thread
Returning several arrays to a view - by El Forum - 08-25-2011, 04:00 PM



Theme © iAndrew 2016 - Forum software by © MyBB