我建立了一个数据表,在该操作项下,单击“编辑”按钮将打开一个模式,该模式显示与被单击的客户有关的所有详细信息。
问题在于,对于模式中显示的每个客户,只有与客户表中输入的第一个客户相关的详细信息,为什么?
代码:
<?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">×</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>
答案 0 :(得分:0)
data-target
必须等于div的ID与客户端的数据:
data-target="#modalRegisterForm-<?= $row['id_cliente'] ?>"
但是如果您的网页上有5-10个客户端,那就可以了。但是,如果每页有50个或100个以上的用户,该怎么办? HTML代码将是巨大的。在这种情况下,您应该编写一个函数以动态生成模式窗口的HTML。您可以使用此answer作为示例。
答案 1 :(得分:0)
我的问题的答案是,标记必须具有自己的#id_modal并且模态必须具有与标记相同的ID。如果模态位于另一页上,显然不要忘记包含。对所有人的编码很好