-6ren">
gpt4 book ai didi

php - 将 mysql 的值传递给 bootstrap modal

转载 作者:行者123 更新时间:2023-11-29 21:57:05 25 4
gpt4 key购买 nike

我想从数据列表中进行选择并在模式弹出窗口中显示所选数据的结果。我只是不知道如何将 id 传递给弹出窗口,以便我可以显示结果。帮助!!

<td> <button class="btn btn-primary " data-toggle="modal" data-id="<?php $id= $row['id'] ?>" data-target="#myModal"  <?php echo"id=$row[id]'";?> >
View Details
</button>
</td>

模式弹出窗口

<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
<h4 class="modal-title" id="myModalLabel">Requisition Details</h4>
</div>
<div class="modal-body">
<?php
$id = $_GET['id'];
include('mysql_connect.php');
$query11 = mysql_query ("select * from p_requisition where id = '$id' ") or die(mysql_error());
$rows= mysql_fetch_array($query11);
echo $rows['details'];
?>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
<!-- /.modal-content -->
</div>
<!-- /.modal-dialog -->
</div>

最佳答案

首先,为按钮添加类可能是get-data

然后在jquery中,

$(document).ready(function() {
$(document).on("click",".get-data"function(){
var val = $(this).attr("data-id");
$.ajax({
url: "path to ajax file",
type: "POST",
dataType: "HTML",
async: false,
success: function(data) {
$('.modal-body').html(data);
}
});

});
});

在ajax文件中,编写查询从mysql获取数据,操作数据并在弹出窗口中显示。

ajax.php

<?php
$id = $_POST['id'];
include('mysql_connect.php');
$query11 = mysql_query ("select * from p_requisition where id = '$id' ") or die(mysql_error());
$rows= mysql_fetch_array($query11);
echo $rows['details'];// here you need to manipulate the database data with html and pass it on to popup.
?>

关于php - 将 mysql 的值传递给 bootstrap modal,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33037797/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com