Php 如何从传递给模态的变量中获取数据?
我有一个带有Php 如何从传递给模态的变量中获取数据?,php,jquery,mysql,ajax,twitter-bootstrap,Php,Jquery,Mysql,Ajax,Twitter Bootstrap,我有一个带有edit和delete按钮的动态表。我能够将变量$parid传递给modal。但是,它没有使用$parid将数据提取到模式中。我不知道我错过了什么。我只想使用mysql代码显示相应的数据,其中parid='$parid'。$parid的值被传递给。以下是我的示例代码: <table id="example" class="table table-striped" > <thead>
edit
和delete
按钮的动态表。我能够将变量$parid
传递给modal。但是,它没有使用$parid
将数据提取到模式中。我不知道我错过了什么。我只想使用mysql代码显示相应的数据,其中parid='$parid'
。$parid
的值被传递给
。以下是我的示例代码:
<table id="example" class="table table-striped" >
<thead>
<tr>
<th>Param ID</th>
<th>Decription</th>
<th>Code</th>
<th></th>
</tr>
</thead>
<tbody>
<?php
require 'lab/db/dbcon.php';
$query = $con->query("SELECT * FROM param");
while($row=mysqli_fetch_array($query)){
?>
<tr>
<td><?php echo $row['parid'];?></td>
<td><?php echo $row['parnam']; ?></td>
<td><?php echo $row['parcod']; ?></td>
<td>
<!--edit button here-->
<a href="" class="btn btn-danger btn-xs btndel" data-toggle="modal" data-id="<?php echo $row['parid']; ?>" data-target="#delpar"><i class="fa fa-trash"></i>
</a>
</td>
</tr>
<?php
}
?>
</tbody>
</table>
<!-- Start Delete Par Modal -->
<div class="modal fade" id="delpar" 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>
<h5 class="modal-title"><i class="fa fa-exclamation-circle"></i> Are you sure to delete this record?</h5>
</div>
<div class="modal-body">
<input type="text" class="form-control" name="parid" id="parid" disabled>
<table id="example" class="table table-bordered">
<thead>
<tr>
<th>Decription</th>
<th>Code</th>
</tr>
</thead>
<tbody>
<?php
require 'lab/db/dbcon.php';
$parid=isset($_POST['parid']);
$query = $con->query("SELECT * FROM param WHERE parid ='$parid' ");
while($row=mysqli_fetch_array($query)){
?>
<tr>
<td><?php echo $row['parnam']; ?></td>
<td><?php echo $row['parcod']; ?></td>
</tr>
<?php
}
?>
</tbody>
</table>
</div>
<div class="modal-footer" style="padding:10px;">
<button type="button" class="btn btn-danger" name="btndel" id="btndel>"> <i class="fa fa-check"></i>
</button>
<button type="button" class="btn btn-default" data-dismiss="modal"><i class="fa fa-remove"></i></button>
</div>
</div>
</div>
</div>
<!-- End Delete Par Modal -->
<script>
$(document).on("click", ".btndel", function () {
var parid = $(this).data('id');
$(".modal-body #parid").val( parid );
$('#delpar').modal('show');
});
</script>
参数ID
描述
代码
&时代;
您确定要删除此记录吗?
描述
代码
您已经忘记了PHP和jQuery代码的范围和时间。jQuery部分:
<script>
$(document).on("click", ".btndel", function () {
var parid = $(this).data('id');
$(".modal-body #parid").val( parid );
$('#delpar').modal('show');
});
</script>
$(文档)。在(“单击”、“.btndel”上,函数(){
var parid=$(this.data('id');
$(“.modal body#parid”).val(parid);
$('delpar').modal('show');
});
在用户查看来自服务器的内容后在用户浏览器上运行。您的“删除PAR模式”中的PHP代码在JQuery甚至到达浏览器之前在服务器上运行。
在jQuery中,您需要添加一个AJAX调用,以实时从服务器获取所需的数据(然后在服务器上运行查询并返回数据)。然后“成功时”,AJAX调用应该填充模式字段。你能告诉我如何根据我的Jquery代码准确地完成它吗?我真的是Ajax的新手。