如何将行的 ID 从我的数据库传递到模式对话框?
How do i pass the ID of a row from my database to a modal dialog?
我有一个模态对话框,我希望它根据特定行的 ID 显示数据库中该行的特定字段。我试图将行 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 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 支付了一个,但没有像 bootstrap 模态一样开箱即用的,每个弹出窗口插件必须编写自定义代码才能在 PHP while 循环内工作,然后下一个问题是在不刷新页面的情况下使用新内容刷新模式。
我使用 bootstrap 模态的方法是,我在你的情况下创建了一个单独的 php 文件 reservation-profile.php
并将文件添加到 href
link 中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
文件
<?php
//Include database connection here
$reserver = $_GET["id"]; //escape the string if you like
$result = mysqli_query($con,"SELECT * FROM general_reservation WHERE reservation_id = '$reserver' ");
//$count = mysqli_num_rows($result); //Don't need to count the rows too
$row = mysqli_fetch_array($result); //Don't need the loop if you wana fetch only single row against id
?>
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title"><center>Reserver</center></h4>
</div>
<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>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
最后也是最重要的部分是在不刷新页面的情况下使用新细节刷新模式。
下面的一段代码可以完成这项工作。你可以阅读更多相关信息 here
注意:将以下代码添加到您调用模态的页面。不要在 reservation-profile.php
中添加
//First jQuery Library
//Bootstrap Library
<script>
$( document ).ready(function() {
$('#myModal').on('hidden.bs.modal', function () {
$(this).removeData('bs.modal');
});
});
</script>
因此整个解决方案开箱即用,无需编写任何额外的代码行。
我有一个模态对话框,我希望它根据特定行的 ID 显示数据库中该行的特定字段。我试图将行 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 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 支付了一个,但没有像 bootstrap 模态一样开箱即用的,每个弹出窗口插件必须编写自定义代码才能在 PHP while 循环内工作,然后下一个问题是在不刷新页面的情况下使用新内容刷新模式。
我使用 bootstrap 模态的方法是,我在你的情况下创建了一个单独的 php 文件 reservation-profile.php
并将文件添加到 href
link 中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
文件
<?php
//Include database connection here
$reserver = $_GET["id"]; //escape the string if you like
$result = mysqli_query($con,"SELECT * FROM general_reservation WHERE reservation_id = '$reserver' ");
//$count = mysqli_num_rows($result); //Don't need to count the rows too
$row = mysqli_fetch_array($result); //Don't need the loop if you wana fetch only single row against id
?>
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title"><center>Reserver</center></h4>
</div>
<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>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
最后也是最重要的部分是在不刷新页面的情况下使用新细节刷新模式。
下面的一段代码可以完成这项工作。你可以阅读更多相关信息 here
注意:将以下代码添加到您调用模态的页面。不要在 reservation-profile.php
//First jQuery Library
//Bootstrap Library
<script>
$( document ).ready(function() {
$('#myModal').on('hidden.bs.modal', function () {
$(this).removeData('bs.modal');
});
});
</script>
因此整个解决方案开箱即用,无需编写任何额外的代码行。