Mount array with result of two querys

0

Good evening. I need your help. Sequinte ...

I'm setting up a function that does a query in the cardapio table, I pass the result of that query to an array, then I make a foreach with that array. Inside this foreach I make a second query in the table item using the ids that contains inside the array ['id'] to bring all the item referring to each menu. So far so good. What I need is to put the result of all this inside a $ array. But I can not. The following is the function I'm doing but I stopped at the mount part of the array.

Thank you in advance.

public function relatorioCardapio($seg="",$tr="",$data=""){

    $array = array();


    $sql = "SELECT c.id id,  s.seguimento seguimento, tr.refeicao refeicao, c.data data FROM
    cardapio c JOIN seguimento AS s ON s.id = c.id_seguimento JOIN tipo_refeicao AS tr
    ON tr.id = c.id_tipo WHERE ";

    $where = array();
    $where[] = "c.id_seguimento = :seg";

    if (!empty($tr)) {
        $where[] = "c.id_tipo = :tr";
    }
    if(!empty($data)){
        $where[] = "c.data = :data";
    }

    $sql .= implode(' AND ', $where);
    //print_r($sql);
    //exit();

    $sql = $this->db->prepare($sql);
    $sql->bindValue(":seg", $seg);  



    if(!empty($tr))
    {
        $sql->bindValue(":tr", $tr);



    }
    if(!empty($data)){

        $sql->bindValue(":data", $data);
    }

    $sql->execute();

    if($sql->rowCount() > 0){

        if($sql->rowCount() > 0){
            $array = $sql->fetchAll();
            foreach ($array as $i)
             {

                $sql = $this->db->prepare("SELECT i.item FROM cardapio c JOIN cad_item AS ci ON ci.id_cardapio = c.id
                                           JOIN item AS i ON i.id = ci.id_item WHERE ci.id_cardapio = :id");
                $sql->bindValue(":id", $i['id']);
                $sql->execute();

                if($sql->rowCount() > 0)
                {
                    $array['item'] = $sql->fetchAll();
                }

            }
            //print_r($array['item']);
            //exit();
        }

    }
    return $array;
}
    
asked by anonymous 19.07.2018 / 01:53

0 answers