Welcome Guest, Not a member yet? Register   Sign In
Help with inserting database result into existing array
#1

[eluser]mandaman2k[/eluser]
Hey,

I've been working on this for a long time and haven't figured it out, this is basically what a need, let me post my model function to give you an idea..
Code:
function getTodo($idShop)
    {
        $this->db->where('Id_Shop', $idShop);
        $this->db->where('Active', 1);
        $this->db->order_by('Prioridad', "asc");
        $query1 = $this->db->get('Shop_Category')->result_array();
        
        foreach($query1 as $row)
        {
            $this->db->where('Id_Shop', $idshop);
            $this->db->where('Active', 1);
            $this->db->where('Shop_Category', $row['Shop_Category']);
            $this->db->order_by('Prioridad', "asc");
            $query2 = $this->db->get('Lists')->result_array();
            
            foreach($query2 as $item)
            {
                $this->db->where('Id_Lists',$item['Id_lists']);
                $this->db->where('Active', 1);
                $query3 = $this->db->get('Lists_Items')->result_array();
                
                $item['Title'] = $query2;
                
                foreach($query3 as $subitem)
                {
                    $this->db->where('Id_ListItem',$subitem['Id_ListItem']);
                    $this->db->where('Active', 1);
                    $query4 = $this->db->get('Cat_Caract')->result_array();
                    
                    $subitem['Value'] = $query3;
                    //$this->firephp->log($subitem);
                }
            }
            $menu[$row['Shop']] = array('Shop' => $row['Shop'], 'lists' => $query2);
        }
        return $menu;
    }

Basically what this function is doing is getting the subitems of each database related by the Id's, for the moment my result array
Code:
array(
  ['menu'] => array(
    ['Shirts'] => array(
    ['Category'] => 'Shirts'
    ['lists'] =>array(
      [0] =>array(
        ['Id_List'] =>3
        ['Id_Shop'] =>1
        ['Name_Product'] =>'T-Shirt'
        ['Description_Product'] =>'Nice T-Shirt'
        ['Price'] =>25
        ['Id_Category'] => 1
        ['Prioridad'] =>1
        ['Active'] =>1
       )
     ['Jeans'] => array(
    ['Categoria'] => 'Jeans'
    ['platos'] =>array(
      [0] =>array(
        ['Id_List'] =>3
        ['Id_Shop'] =>1
        ['Name_Product'] =>'Hot Cakes'
        ['Description_Product'] =>'3 Hot Cakes'
        ['Price'] =>25
        ['Id_Category'] => 2
        ['Prioridad'] =>1
        ['Active'] =>1
       )
    )
)

Now, what query 2 and 3 are doing is for example is extracting the size,colors,print,etc... and there values: L,M,S,Red, etc...of each product.

In table 2 the title is whats being saved and retrieved (Size, Colors, print, etc.)
In table 3 the value is whats being saved and retrieved (L,M,S, Red,Blue,etc.)
depending on the product.

Each product, might have one caracteristic, or both or many more, or none, it aint matter it depends on the product.

So what a I need is that after de
Quote:['Active']
I get a new array with the name
Quote:['Title'] => array(...
and under title after its last column i need
Quote:['Value'] = array(...
, basically its a 3 subs of array. (jejeje, kind of like a inception, :-P )

What i can do until know is getting the category(getTodo) and product(query1) in the same array which I showed you and title(query2) and value(query3) in an another array with the same structure as shown before, all i need is to get 2 and 3 on the same array as getTodo and 1.

ohh and what's happing now in 2 and 3 is that only the las retrieved result is getting saved not all the results from the query.

So basically what i want my end product to be is this:
Code:
array(
  ['menu'] => array(
    ['Shirts'] => array(
    ['Category'] => 'Shirts'
    ['lists'] =>array(
      [0] =>array(
        .
        .
        .
        .
        ['Active'] =>1
        ['Title'] = > array (
          [0] =>array(
            .
            .
            .
           ['LastColumn'] =>1
           ['Value'] => array(
             [0] => array(
              .
              .
              .
              .
             )
          [1] => array(
            .
            .
            .
           ['LastColumn'] =>1
           ['Value'] => array(
             [0] => array(
              .
              .
              .
              .
             )
          )
       )
    )
)

Hope someone could help, I would greatly appreciate it.

Being thinking about stored procedures, but i don't really know a lot about them.

Thanks
Isaac




Theme © iAndrew 2016 - Forum software by © MyBB