我有这两个表,分别是table1.php和table2.php
我可以使用此脚本将数据传递给模式,该脚本位于table1.php中,并且可以通过模式将数据传递至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>
答案 0 :(得分:0)
所以..问题是您必须在同一页面上提交:并在同一页面的模式窗口中解析$_POST
数组,因为它包含在此处。
试试这个:
table1.php:
<form method="POST" action="table1.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
<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
if(isset($_POST['seriesno'])){
$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>
希望它能发挥作用