【问题标题】:Modal inserted into a datatable shows only first record of the table插入数据表的模态仅显示表的第一条记录
【发布时间】:2018-12-16 13:53:51
【问题描述】:

我在操作项下方构建了一个数据表,单击编辑按钮会打开一个模式,其中显示与单击的客户相关的所有详细信息。

问题是,对于模态中显示的每个客户,只有与在客户表中输入的第一个客户相关的详细信息,为什么?

代码:

       <?php
       while($row = mysqli_fetch_assoc($query)){ ?>

        <!--Table body-->
        <tbody>
            <tr>
                <th scope="row">
                    <label class="form-check-label" for="checkbox1" class="label-table"></label>
                </th>
                <td style="vertical-align: middle;"><?php echo $row['nome_cliente'] ;?></td>
                <td style="vertical-align: middle;"><?php echo $row['cognome_cliente'] ;?></td>
                <td style="vertical-align: middle;"><?php echo $row['azienda_cliente'] ;?></td>
                <td style="vertical-align: middle;"><?php echo $row['telefono_cliente'] ;?></td>
                <td style="vertical-align: middle;"><?php echo $row['email_cliente'] ;?></td>

                <td style="vertical-align: middle;">
                <a href="#modifica_cliente=<?php echo $row['id_cliente']; ?>" data-toggle="modal" data-target="#modalRegisterForm" class="btn btn-primary btn-sm btn-rounded">MODIFICA</a>  
                <?php include('modali/modifica.php'); ?>
                </td>



            </tr>


        </tbody>
        <?php } ?>
        <!--Table body-->
    </table>
    <!--Table-->
</div>

模态代码:

<?php
$query_client=mysqli_query($connessione,"SELECT * FROM ca2_2ac_clienti WHERE id_cliente='".$row['id_cliente']."'");
$details=mysqli_fetch_array($query_client);
?>

<div class="modal fade" id="modalRegisterForm" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header text-center">
                <h4 class="modal-title w-100 font-weight-bold">Modifica <?php echo $details['nome_cliente'].$details['cognome_cliente'] ;?></h4>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <div class="modal-body mx-3">
                <div class="md-form mb-5">
                    <i class="fa fa-user prefix grey-text"></i>
                    <input type="text" id="orangeForm-name" value="<?php echo $details['nome_cliente'] ;?>" class="form-control validate">
                    <label data-error="wrong" data-success="right" for="orangeForm-name">Nome Cliente</label>
                </div>
                <div class="md-form mb-5">
                    <i class="fa fa-user prefix grey-text"></i>
                    <input type="text" id="orangeForm-email" value="<?php echo $details['cognome_cliente'] ;?>" class="form-control validate">
                    <label data-error="wrong" data-success="right" for="orangeForm-email">Cognome Cliente</label>
                </div>

                <div class="md-form mb-5">
                    <i class="fa fa-user prefix grey-text"></i>
                    <input type="text" id="orangeForm-email" value="<?php echo $details['azienda_cliente'] ;?>" class="form-control validate">
                    <label data-error="wrong" data-success="right" for="orangeForm-email">Azienda Cliente</label>
                </div>


                <div class="md-form mb-5">
                    <i class="fa fa-user prefix grey-text"></i>
                    <input type="text" id="orangeForm-email" value="<?php echo $details['telefono_cliente'] ;?>" class="form-control validate">
                    <label data-error="wrong" data-success="right" for="orangeForm-email">Telefono Cliente</label>
                </div>



                <div class="md-form mb-5">
                    <i class="fa fa-user prefix grey-text"></i>
                    <input type="text" id="orangeForm-email" value="<?php echo $details['email_cliente'] ;?>" class="form-control validate">
                    <label data-error="wrong" data-success="right" for="orangeForm-email">Email Cliente</label>
                </div>

            </div>
            <div class="modal-footer d-flex justify-content-center">
                <button class="btn btn-deep-orange">Sign up</button>
            </div>
        </div>
    </div>
</div>

【问题讨论】:

    标签: php mysqli bootstrap-modal


    【解决方案1】:

    data-target 必须等于 div 的 id 与客户端的数据:

    data-target="#modalRegisterForm-&lt;?= $row['id_cliente'] ?&gt;"

    但是,如果您的网页上有 5-10 个客户,那就没问题了。但是,如果每页有 50 或 100 多个用户怎么办? HTML 代码会很大。在这种情况下,您应该编写一个函数来动态构建模态窗口的 HTML。你可以以这个answer 为例。

    【讨论】:

      【解决方案2】:

      我的问题的答案是标签必须有自己的#id_modal 并且模态必须具有相同的标签 id 如果模态在另一个页面上,显然不要忘记包含。对每个人都很好的编码

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-09-13
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-06-11
        相关资源
        最近更新 更多