【发布时间】:2019-07-29 02:14:33
【问题描述】:
我有这两张表,分别是table1.php和table2.php
我可以使用这个脚本将数据传递给一个modal,这个脚本在table1.php中,它可以通过modal将数据传递给table2.php,我现在关心的是如何将数据直接传递给table2.php SQL 查询?由于它的方式,我只能使用传递给 HTML 元素的模式的数据。有没有办法传递模态值并将其转换为 PHP 的 SQL 查询?
$(function(){
$("body").on('click', '.edit', function (e){
e.preventDefault();
$('#edit').modal('show');
var id = $(this).data('id');
getRow(id);
});
我正在尝试将选定的数据行传递到另一个 PHP 页面,以便它将成为过滤第二个 PHP 表的参数。
这是我的table1.php
<form type="POST" action="table2.php">
<table id="example1" class="table table-bordered">
<thead>
<th>Series No.</th>
<th>Account Type</th>
<th>Tools</th>
</thead>
<tbody>
<?php
$sql = "SELECT * FROM accounttype";
$query = sqlsrv_query($conn, $sql, array(), array("Scrollable" => SQLSRV_CURSOR_KEYSET));
while($row = sqlsrv_fetch_array($query, SQLSRV_FETCH_ASSOC)){
echo "
<tr>
<td>".$row['seriesno']."</td>
<td>".$row['accounttype']."</td>
<td>
<button class='btn btn-success btn-sm edit btn-flat' data-id='".$row['seriesno']."'><i class='fa fa-edit'></i> Edit</button>
<button class='btn btn-danger btn-sm delete btn-flat' data-id='".$row['seriesno']."'><i class='fa fa-trash'></i> Delete</button>
</td>
</tr>
";
}
?>
</tbody>
</table>
</form>
这将是我的 table2.php
<table id="example2" class="table table-bordered">
<thead>
<th>Series No.</th>
<th>Account Type</th>
</thead>
<tbody>
<?php
$id=$_POST['seriesno'];
$sql = "SELECT * FROM accounttype where seriesno='$id'";
$query = sqlsrv_query($conn, $sql, array(), array("Scrollable" => SQLSRV_CURSOR_KEYSET));
while($row = sqlsrv_fetch_array($query, SQLSRV_FETCH_ASSOC)){
echo "
<tr>
<td>".$row['seriesno']."</td>
<td>".$row['accounttype']."</td>
</tr>
";
}
?>
</tbody>
</table>
问题是 table2.php 无法接收到 $_POST,这似乎是什么问题?
编辑:这是我的模式 (table2.php) 我需要将数据传递到表中,以便 $id=$_POST['seriesno']; 可以工作。
<div class="modal fade" id="edit">
<div class="modal-dialog" style="width:100%;">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span></button>
</div>
<div class="modal-body">
<input type="hidden" class="decid" id="id" name="id">
<table id="example2" class="table table-bordered">
<thead>
<th>Series No.</th>
<th>Account Type</th>
</thead>
<tbody>
<?php
$id=$_POST['seriesno'];
$sql = "SELECT * FROM accounttype where seriesno='$id'";
$query = sqlsrv_query($conn, $sql, array(), array("Scrollable" => SQLSRV_CURSOR_KEYSET));
while($row = sqlsrv_fetch_array($query, SQLSRV_FETCH_ASSOC)){
echo "
<tr>
<td>".$row['seriesno']."</td>
<td>".$row['accounttype']."</td>
</tr>
";
}
?>
</tbody>
</table>
</div>
</div>
</div>
</div>
【问题讨论】:
-
你在哪里发帖到 table2?
-
@MoisheSchwartz
$id=$_POST['seriesno'];,我正在尝试将选定的 dataTable 值传递给 table2.php -
@pjustindaryll,我上面的评论者询问您尝试将数据提交到另一个 .php 脚本的表单在哪里?显示您的模态 html。
-
@SergheiLeonenco 抱歉,我正在尝试将其提交到另一个 .php 页面。
-
@SergheiLeonenco 我可以使用脚本将数据传递给模态,这个脚本在table1.php中,它可以通过模态将数据传递到table2.php,我现在关心的是我将如何传递数据直接进入 table2.php 的 SQL 查询,而不是通过模态传递?
标签: php jquery html ajax sqlsrv