Welcome Guest, Not a member yet? Register   Sign In
Issue with arrays? Any experts?
#2

[eluser]Devon Lambert[/eluser]
Ok,

Narrowed this one down and figured out that it purely my lack of knowledge with arrays that is hurting me here. I'm close but still don't quite have a solution, any help is greatly appreciated.

Here is what I have so far:

MODEL:

Code:
function get_categories() {  
    $query = "SELECT name, type FROM categories ORDER BY categories.order ASC";
    $result = $this->db->query($query);
    return $result->result_array();
}
    
function get_catgames($cat_data) {
    foreach ($cat_data['categories'] as $category):
    $query = "SELECT id, items.desc, name, nameid, rating  FROM items WHERE cat = '".$category['name']."' ORDER BY RAND() LIMIT 0, 5";            
        $result = $this->db->query($query);
    return $result->result_array();
    endforeach;
}

CONTROLLER:

Code:
// Create the cat_data array
    $cat_data = array();
        
    $cat_data['categories'] = $this->mdl_home->get_categories();
    $cat_data['items'] = $this->mdl_home->get_catitems($cat_data);
        
    //Printing out my array for testing purposes
    print_r($cat_data);
        
    $this->load->view('home_bottom', $cat_data);

VIEW:

Code:
<?php foreach($categories as $category):?>
  <li>&lt;?php echo "<br />".$category['name'];?&gt;</li>
      <ul>
      &lt;?php foreach($items as $item):?&gt;
      <li>&lt;?php echo $item['name']; ?&gt;</li>    
      &lt;?php endforeach;?&gt;
      </ul>
&lt;?php endforeach;?&gt;

This code is currently outputting the same "items" for every category that I print out. Such as:

#


Category 1

* BLUE Item 1
* BLUE Item 2
* BLUE Item 3
* BLUE Item 4
* BLUE Item 5

Different category but same items?

Category 2

* BLUE Item 1
* BLUE Item 2
* BLUE Item 3
* BLUE Item 4
* BLUE Item 5

etc...


Messages In This Thread
Issue with arrays? Any experts? - by El Forum - 05-26-2008, 01:11 AM
Issue with arrays? Any experts? - by El Forum - 05-26-2008, 05:33 PM
Issue with arrays? Any experts? - by El Forum - 05-26-2008, 05:51 PM
Issue with arrays? Any experts? - by El Forum - 05-26-2008, 06:02 PM
Issue with arrays? Any experts? - by El Forum - 05-26-2008, 06:06 PM
Issue with arrays? Any experts? - by El Forum - 05-26-2008, 06:15 PM
Issue with arrays? Any experts? - by El Forum - 05-26-2008, 06:16 PM
Issue with arrays? Any experts? - by El Forum - 05-26-2008, 07:10 PM
Issue with arrays? Any experts? - by El Forum - 05-26-2008, 07:36 PM
Issue with arrays? Any experts? - by El Forum - 05-26-2008, 07:37 PM
Issue with arrays? Any experts? - by El Forum - 05-26-2008, 08:24 PM
Issue with arrays? Any experts? - by El Forum - 05-26-2008, 08:28 PM
Issue with arrays? Any experts? - by El Forum - 05-26-2008, 08:32 PM
Issue with arrays? Any experts? - by El Forum - 05-26-2008, 08:59 PM
Issue with arrays? Any experts? - by El Forum - 05-26-2008, 09:02 PM
Issue with arrays? Any experts? - by El Forum - 05-27-2008, 12:09 AM



Theme © iAndrew 2016 - Forum software by © MyBB