我在foreach中的foreach中得到一个空表:php

时间:2018-09-24 11:23:31

标签: php mysql

当用户以表格的形式添加许多学校时,例如3, 将会出现另一个表格,其中包含3行,其中包含这3所学校的信息,最后,我将两个表格的内容添加到两个表中。

在第一个wp_mairie_details中,我添加了用户信息。 在第二张表中,我添加了学校的信息。

我想显示用户列表以及最后添加到表单中的学校。 我的第一个循环显示正确,但是第二个循环显示了正确的学校数量,但是我得到了一个空表。

        <?php               
            foreach ( $dump_ecoles_classes_1 as $i => $ecoles_classe ) {
        ?>
        <div class="abonn_style">
            <span class="span_abonn_style">Nomde la mairie :</span><br>
            <input type="text" name="nom_mairie" value="<?php echo  $dump_ecoles_classes_1[$i]['nom_mairie']; ?>" disabled class="span_abonn_style"> 
            <br>
            <span class="span_abonn_style">Adresse:</span><br>
            <textarea rows="4" cols="50" name="adress"  value="<?php echo   $dump_ecoles_classes_1[$i]['adress']; ?>" disabled class="span_abonn_style">
                </textarea>
            <br> 
            <span class="span_abonn_style">Responsable du projet:</span><br>
            <input type="text" class="span_abonn_style" name="responsable" value="<?php echo    $dump_ecoles_classes_1[$i]['responsable']; ?>" disabled>

            <br>
            <span class="span_abonn_style">E-mail:</span><br>
            <input type="email" class="span_abonn_style" name="email" value="<?php echo $dump_ecoles_classes_1[$i]['email']; ?>" disabled>   
            <br>
            <span class="span_abonn_style">Nombre de ecoles:</span><br>
            <input type="number" name="ecoles" class="span_abonn_style" value="<?php echo   $dump_ecoles_classes_1[$i]['ecoles']; ?>" disabled >

            <br>


            <?php 

            $i_var = $dump_ecoles_classes_1[$i]['ecoles'];

            $mairie_ecoles_row = $wpdb->get_results("SELECT DISTINCT me.nom_ecole_mairie,me.responsable_mairie,me.email_mairie,me.nbr_classes_mairie,me.nbr_eleves_mairie,me.id_user FROM wp_mairie_ecoles me 
            INNER JOIN wp_mairie_details md ON md.id_user = me.id_user 
            INNER JOIN wp_pmpro_membership_orders mo ON mo.user_id = md.id_user 
            where me.id_user = '".$dump_ecoles_classes_1[$i]['id_user']."'
            order by md.id_user");


            $row_mairie_ecoles = objectToArray($mairie_ecoles_row);



            foreach ( $row_mairie_ecoles as $k => $row_mairie_ecole ) {
            ?>
            <table class="trios_table">
            <tr class="trios_tr_style">
                <th style="border: 2px solid black!important;background: #e4e4e4;">Nom de l’école
                </th>                                       
                <th style="border: 2px solid black!important;background: #e4e4e4;">responsable
                </th>                                     
                <th style="border: 2px solid black!important;background: #e4e4e4;">email
                </th>                                       
                <th style="border: 2px solid black!important;background: #e4e4e4;">Nbre/classes
                </th> 
                <th style="border: 2px solid black!important;background: #e4e4e4;">Nbre/élèves
                </th> 
            </tr>

            <tr class="trios_tr_style">
                <td class="trios_td_style trios_td_style_1 ">
                <?php   
                echo    $row_mairie_ecoles[$k]['nom_ecole_mairie'];

                ?>
                </td>
                <td class="trios_td_style trios_td_style_1 ">
                <?php 
                    echo    $row_mairie_ecoles[$k]['responsable_mairie'];

                ?>
                </td>
                <td class="trios_td_style trios_td_style_1 ">
                <?php 
                    echo    $row_mairie_ecoles[$k]['email_mairie'];
                ?>
                </td>
                <td class="trios_td_style trios_td_style_1 ">
                <?php 
                    echo    $row_mairie_ecoles[$k]['nbr_classes_mairie'];
                ?>
                </td>
                <td class="trios_td_style trios_td_style_1 ">
                <?php 
                    echo    $row_mairie_ecolesrow_mairie_ecoles[$k]['nbr_eleves_mairie'];
                    ?>
                </td>
            </tr>

        </table>
        <?php   // } ?>

        </div>
        <?php } ?>
    </div>

1 个答案:

答案 0 :(得分:0)

尝试

<?php               
            foreach ( $dump_ecoles_classes_1 as $i => $ecoles_classe ) {
        ?>
        <div class="abonn_style">
            <span class="span_abonn_style">Nomde la mairie :</span><br>
            <input type="text" name="nom_mairie" value="<?php echo  $dump_ecoles_classes_1[$i]['nom_mairie']; ?>" disabled class="span_abonn_style"> 
            <br>
            <span class="span_abonn_style">Adresse:</span><br>
            <textarea rows="4" cols="50" name="adress"  value="<?php echo   $dump_ecoles_classes_1[$i]['adress']; ?>" disabled class="span_abonn_style">
                </textarea>
            <br> 
            <span class="span_abonn_style">Responsable du projet:</span><br>
            <input type="text" class="span_abonn_style" name="responsable" value="<?php echo    $dump_ecoles_classes_1[$i]['responsable']; ?>" disabled>

            <br>
            <span class="span_abonn_style">E-mail:</span><br>
            <input type="email" class="span_abonn_style" name="email" value="<?php echo $dump_ecoles_classes_1[$i]['email']; ?>" disabled>   
            <br>
            <span class="span_abonn_style">Nombre de ecoles:</span><br>
            <input type="number" name="ecoles" class="span_abonn_style" value="<?php echo   $dump_ecoles_classes_1[$i]['ecoles']; ?>" disabled >

            <br>


            <?php 

            $i_var = $dump_ecoles_classes_1[$i]['ecoles'];

            $mairie_ecoles_row = $wpdb->get_results("SELECT DISTINCT me.nom_ecole_mairie,me.responsable_mairie,me.email_mairie,me.nbr_classes_mairie,me.nbr_eleves_mairie,me.id_user FROM wp_mairie_ecoles me 
            INNER JOIN wp_mairie_details md ON md.id_user = me.id_user 
            INNER JOIN wp_pmpro_membership_orders mo ON mo.user_id = md.id_user 
            where me.id_user = '".$dump_ecoles_classes_1[$i]['id_user']."'
            order by md.id_user");


            $row_mairie_ecoles = objectToArray($mairie_ecoles_row);

            foreach ( $row_mairie_ecoles as $k => $row_mairie_ecole ) {
            ?>
            <table class="trios_table">
            <tr class="trios_tr_style">
                <th style="border: 2px solid black!important;background: #e4e4e4;">Nom de l’école
                </th>                                       
                <th style="border: 2px solid black!important;background: #e4e4e4;">responsable
                </th>                                     
                <th style="border: 2px solid black!important;background: #e4e4e4;">email
                </th>                                       
                <th style="border: 2px solid black!important;background: #e4e4e4;">Nbre/classes
                </th> 
                <th style="border: 2px solid black!important;background: #e4e4e4;">Nbre/élèves
                </th> 
            </tr>

            <tr class="trios_tr_style">
                <td class="trios_td_style trios_td_style_1 ">
                <?php   
                echo    $row_mairie_ecoles[$k]['nom_ecole_mairie'];
                ?>
                </td>
                <td class="trios_td_style trios_td_style_1 ">
                <?php 
                    echo    $row_mairie_ecoles[$k]['responsable_mairie'];

                ?>
                </td>
                <td class="trios_td_style trios_td_style_1 ">
                <?php 
                    echo    $row_mairie_ecoles[$k]['email_mairie'];
                ?>
                </td>
                <td class="trios_td_style trios_td_style_1 ">
                <?php 
                    echo    $row_mairie_ecoles[$k]['nbr_classes_mairie'];
                ?>
                </td>
                <td class="trios_td_style trios_td_style_1 ">
                <?php 
                    echo    $row_mairie_ecolesrow_mairie_ecoles[$k]['nbr_eleves_mairie'];
                    ?>
                </td>
            </tr>

        </table>
        <?php    } ?>

        </div>
        <?php } ?>
    </div>