脚本宝典收集整理的这篇文章主要介绍了将PHP变量传递给bootstrap模式,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一行代码用于按钮,它为表的每一行再次创建,每个按钮具有基于该记录的id的不同值.
$order .= '<td><a href="#myModal" class="BTn btn-default btn-small" id="custId" data-toggle="modal" data-id="'.$row['ID'].'">EdIT</a></td>';
问题是我想使用$row [‘ID’]并以模态查看它,所以我可以使用MysqLi查询检索具有相同ID的记录.
这是模态的代码.
<div class="modal fade" id="myModal" role="diaLOG"> <div class="modal-dialog"> <!-- Modal content--> <div class="modal-content"> <div class="modal-header"> <button tyPE="button" class="close" data-dismiss="modal">&times;</button> <h4 class="modal-title">Edit Data</h4> </div> <div class="modal-body"> i want to save the id in a VARiable here so i can use it in a PHP script for this modal </div> <div class="modal-footer"> <button type="button" class="btn btn-default" data-dismiss="modal">Close</button> </div> </div> </div> </div>
带有$row [‘ID’]的模态触发按钮
$order .= '<td><a href="#myModal" class="btn btn-default btn-small" id="custId" data-toggle="modal" data-id="'.$row['ID'].'">Edit</a></td>';
使用Ajax方法获取$row [‘ID’]值的Bootstrap Modal事件
$(document).ready(function(){ $('#myModal').on('show.bs.modal',function (e) { var rowid = $(e.relatedTarget).data('id'); $.ajax({ type : 'post',url : 'fetch_record.PHP',//Here you will fetch records data : 'rowid='+ rowid,//Pass $id success : function(data){ $('.fetched-data').htML(data);//Show fetched data From database } }); }); });
模态HTML
<div class="modal fade" id="myModal" role="dialog"> <div class="modal-dialog" role="document"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal">×</button> <h4 class="modal-title">Edit Data</h4> </div> <div class="modal-body"> <div class="fetched-data"></div> //Here Will show the Data </div> <div class="modal-footer"> <button type="button" class="btn btn-default" data-dismiss="modal">Close</button> </div> </div> </div> </div>
最后创建fetch_record.PHP,检索记录并以模态显示
<?PHP //Include database connection if($_POST['rowid']) { $id = $_POST['rowid']; //escape string // Run the Query // Fetch Records // Echo the data you want to show in modal } ?>
以上是脚本宝典为你收集整理的将PHP变量传递给bootstrap模式全部内容,希望文章能够帮你解决将PHP变量传递给bootstrap模式所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。