尝试提取数据时

时间:2018-05-17 13:28:41

标签: php mysql arrays pdo

我在这些菜单中有菜单(食物)我有子菜单(第一,第二等),在子菜单中我有菜。

子菜单我生成它们是完美的,一旦菜肴总是用最后一个子菜单的最后菜肴填充它们,我总是在所有子菜单中得到相同的菜肴aunq是不同的。

问题在于,当我尝试使用菜单获取子菜单时,只需取最后一个值。

我有2个子菜单​​,但在两个菜单中我都使用相同的盘子,我只想在每个子菜单中只取一个子菜单的盘子。

菜单Crud,

 /*SUBMENUS DE UN MENU*/
public function justSubMenu($arrayMenu,$id_menu){
    $result = [];
    foreach ($arrayMenu as $key => $value) {
        if($value['id'] == $id_menu) {
            array_push($result, $value['nombre']);

        }
    }
    return array_unique($result);;
}
/*PLATOS DE UN SUBMENU*/
public function platosSubMenu($arrayMenu,$id_submenu){
    $result = [];
    foreach ($arrayMenu as $key => $value) {
        if ($value[3] == $id_submenu) {
            array_push($result, $value[0]);
        }
    }
    return $result;
}

当我显示数据时,

<?php
$infoMenu = $crudMenu->platosMenu($_GET['id_menu']);

$submenus = $crudMenu->justSubMenu($infoMenu,194);


foreach ($infoMenu as $key => $value) {
    $info = $crudMenu->platosSubMenu($infoMenu,$infoMenu[$key][3]);
}

?>
<div class="container-fluid platos p-0 m-0">
    <div class="first">
        <?php foreach ($submenus as $key => $value) { ?>
        <div class="cabecal row flex-parent">
            <section class="col-xs-10 col-sm-10 col-md-10 col-lg-10">
                <div class="cabecalTitle flex-child">
                    <h2><?php echo $value ?></h2>
                </div>
            </section>
        </div>


        <div class="row groupDish">
            <?php foreach ($info as $key => $value) { ?>
            <article class="col-xs-12 col-sm-6 col-md-6 col-lg-6 float-left">
                <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
                    <h3 class="nameDish"><?php echo $value; ?></h3>
                </div>
                <div class="price">
                    <span><!-- <?php // echo $value[]; ?> --></span>
                </div>
            </article>
            <?php } ?>
        </div>
        <?php } ?>
    <div>
</div>

我从每个阵列得到什么,

ARRAY INFOMENU
Array (
    [0] => Array (
        [nombre] => NOMBRE DEL SUBMENU 2
        [0] => plato 1
        [precio] => 0
        [1] => 0 [2] => NOMBRE DEL SUBMENU 2
        [id] => 194
        [3] => 141 [4] => 194 
    )
    [1] => Array (
        [nombre] => NOMBRE DEL SUBMENU 2
        [0] => plato 2
        [precio] => 0
        [1] => 0
        [2] => NOMBRE DEL SUBMENU 2
        [id] => 194
        [3] => 141
        [4] => 194
    )
    [2] => Array (
        [nombre] => NOMBRE DEL SUBMENU
        [0] => plato aulacampius 2
        [precio] => 0
        [1] => 0
        [2] => NOMBRE DEL SUBMENU
        [id] => 194
        [3] => 140
        [4] => 194 )
    )
ARRAY INFO
Array (
        [0] => plato aulacampius 2
)
ARRAY SUBMENUS
Array (
    [0] => NOMBRE DEL SUBMENU 2
    [2] => NOMBRE DEL SUBMENU
) 

0 个答案:

没有答案