Php 如何将数据库中的行ID传递给模式对话框?
我有一个模式对话框,我希望它根据特定行的ID显示数据库中某行的特定字段。我正试图将行ID从数据库传递到模式对话框,以便我可以使用它进行查询,但我遇到了挑战,我如何才能做到这一点Php 如何将数据库中的行ID传递给模式对话框?,php,mysqli,modal-dialog,Php,Mysqli,Modal Dialog,我有一个模式对话框,我希望它根据特定行的ID显示数据库中某行的特定字段。我正试图将行ID从数据库传递到模式对话框,以便我可以使用它进行查询,但我遇到了挑战,我如何才能做到这一点 <?php $result = mysqli_query($con,"SELECT * FROM general_reservation "); $count = mysqli_num_rows($result); echo "<b><center><h3>C
<?php
$result = mysqli_query($con,"SELECT * FROM general_reservation ");
$count = mysqli_num_rows($result);
echo "<b><center><h3>Cars Reserved By Districts</h3></center></b><br><br>";
while($row=mysqli_fetch_array($result)){
$reservation_id = $row['reservation_id'];
?>
<tr>
<td><a name="reserver" data-id="myModal" class="btn btn-link" data-toggle="modal" href="#myModal" >Reserver's Profile</a></td>
</tr>
<?php
$reserver = $row['reservation_id'];
} //end of while loop ?>
</tbody>
</table>
<div class="modal fade" id="myModal" role="dialog">
<div class="modal-dialog modal-sm">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title"><center>Reserver</center></h4>
</div>
<?php
$reserver = $row['reservation_id'];
$reservation_id = 'reservation_id' ;
$result = mysqli_query($con,"SELECT * FROM general_reservation WHERE reservation_id = '$reserver' ");
$count = mysqli_num_rows($result);
while($row=mysqli_fetch_array($result)){
?>
<div class="modal-body">
<p ><strong>First Name: </strong><?php echo $row['fname'];?> </p><br>
<p ><strong>Last Name: </strong><?php echo $row['lname'];?></p><br>
<p ><strong>Mobile Number: </strong><?php echo $row['mobile_number'];?></p>
</div>
<?php } //end of while loop ?>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
&时代;
保护
我也遇到了同样的问题,我试过jQuery对话框,许多已知和未知的弹出式插件甚至从codecanyon支付了一个,但没有任何东西像引导模式那样在盒子里工作,每个弹出式插件都必须编写自定义代码在PHP内部工作,而循环,然后下一个问题是在不刷新页面的情况下使用新内容刷新模式
我使用bootstrap模式的方法是,我在您的案例中创建了一个单独的php文件reservation profile.php
,并将该文件添加到href
链接中,并使用id
调用弹出模式
<?php
$result = mysqli_query($con,"SELECT * FROM general_reservation ");
$count = mysqli_num_rows($result);
echo "<b><center><h3>Cars Reserved By Districts</h3></center></b><br><br>";
while($row=mysqli_fetch_array($result)){
$reservation_id = $row['reservation_id'];
?>
<tr><td>
<a data-toggle="modal" href="reservation-profile.php?id=<?php echo $reservation_id;?>" data-target="#myModal" class="btn btn-link">Reserver's Profile</a>
</td></tr>
<?php
//$reserver = $row['reservation_id']; //Don't Need this
} //end of while loop
?>
//Bootstrap Modal
<div class="modal fade" id="myModal">
<div class="modal-dialog modal-sm">
<div class="modal-content">
<strong>Loading...</strong>
</div>
</div>
</div>
最后也是最重要的部分是在不刷新页面的情况下使用新的细节刷新模式
下面是一段代码。您可以阅读更多关于它的信息
注意:将以下代码添加到调用模式的页面。不要将此添加到reservation profile.php
//First jQuery Library
//Bootstrap Library
<script>
$( document ).ready(function() {
$('#myModal').on('hidden.bs.modal', function () {
$(this).removeData('bs.modal');
});
});
</script>
//第一个jQuery库
//引导程序库
$(文档).ready(函数(){
$('#myModal').on('hidden.bs.modal',function(){
$(this.removeData('bs.modal');
});
});
因此,整个解决方案是开箱即用的,无需编写任何额外的代码。您可能需要使用js。@EmmanuelGamor,按照您目前的方法,即使您能够使用js传递id,下一个挑战是如何卸载数据并根据新id加载新数据,而无需页面引用,@Shehary我真的想过,但我想是否还有其他方法可以实现同样的目标?@EmmanuelGamor,有一种方法,但你目前的方法是不可能的,我也有同样的问题,我试着和你一样的方法,但没有成功,所以我做了一些改变,它对甲烷非常有效,因为我已经寻找了很长时间的解决方案。但现在,一个挑战是,在我可以通过单击不同的“Reserver的配置文件”调用不同的模式对话框之前,必须刷新页面。现在,它只加载链接的模式对话框,在页面刷新后首先单击该对话框。我没有理解您,你需要刷新页面或页面刷新自己,同时每次单击链接或模式以相同的细节打开?我的意思是,我需要刷新页面,然后才能看到具有不同细节的新模型,而不是模式每次以相同的细节打开。它现在工作得很好。我所做的是在模式对话框的关闭按钮上添加了一个重载功能<代码>关闭
@Shehary回答得很好。
//First jQuery Library
//Bootstrap Library
<script>
$( document ).ready(function() {
$('#myModal').on('hidden.bs.modal', function () {
$(this).removeData('bs.modal');
});
});
</script>