Welcome Guest, Not a member yet? Register   Sign In
parent-child problem
#1

[eluser]dimis[/eluser]
I have 3 tables.
One it the products, the second is the text for each product for each language (English,german etc).
The other is some information for each product.
I have this code at my model
Code:
function ReturnTopTen($id,$lan)
    {
        $data = array();
        $this->db->select('id,note');
        $this->db->from('products_view');
        $this->db->where("visible='1'and lan_code='$lan'");
        $this->db->limit(10);
        $query= $this->db->get();
        if ( $query-> num_rows() > 0){
            foreach ( $query-> result_array() as $row){
                $data['product'][] = $row;
                $data['code'][]=$this->ReturnFirstColor($id);
            }
            return $data;
        }
    }
    function ReturnFirstColor($id)
    {
        $data = array();
        $this->db->select('code_photo');
        $this->db->from('product_code');
        $this->db->where("product_id=",$id);
        $this->db->limit(1);
        $query= $this->db->get();
        if ( $query-> num_rows() > 0){
            foreach ( $query-> result() as $row){

                $data['code_photo'] = $row->code_photo;
            }
            return $data;
        }
    }
and I call this at controller
Code:
$this->data['producer'] = $this->client_producer->ReturnProducer($a,$this->session->userdata('lan'));
{  $mykey="'$key'";
            echo $list['code_photo'];;          
        }
But there is an error
Quote:Severity: Notice
Message: Undefined index: 'product','code'
How can I do loop at this array and to take the values or maybe another way?
Dimis
#2

[eluser]GSV Sleeper Service[/eluser]
you could do a join on products_view and products_code, this would save you doing two queries.
also, your error is being produced by ReturnProducer(), and you haven't given example code for that method.
#3

[eluser]dimis[/eluser]
Sorry the right method for this is
$this->data['top_ten'] = $this->client_producer->ReturnTopTen($a,$this->session->userdata('lan'));
Thank you
#4

[eluser]dimis[/eluser]
My problem is that at the 3rd table there are many records for the first table.
How generally we fetch records from a table and one field related with the parent record at mysql?




Theme © iAndrew 2016 - Forum software by © MyBB