将选定的 dataTable 行传递到另一个 php 页面中的另一个 dataTable 行
Pass selected dataTable row to another dataTable row in another php page
我有这两个table,即table1.php和table2.php
我可以使用这个脚本将数据传递给模态,这个脚本在table1.php中,它可以通过模态将数据传递给table2.php,我现在关心的是如何传递数据直接进入 table2.php 的 SQL 查询?由于它的方式,我只能使用传递给 HTML 元素的模态的数据。有没有办法传递模态值并将其转换为 SQL 查询 PHP?
$(function(){
$("body").on('click', '.edit', function (e){
e.preventDefault();
$('#edit').modal('show');
var id = $(this).data('id');
getRow(id);
});
我正在尝试将选定的数据行传递到另一个 PHP 页面,以便它将成为过滤第二个 PHP table.
的参数
这是我的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) 我需要的是将数据传递到 table 以便 $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>
所以.. 问题是您必须在同一页面上提交:并在同一页面中解析模态 window 中的 $_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>
希望它有所帮助
我有这两个table,即table1.php和table2.php
我可以使用这个脚本将数据传递给模态,这个脚本在table1.php中,它可以通过模态将数据传递给table2.php,我现在关心的是如何传递数据直接进入 table2.php 的 SQL 查询?由于它的方式,我只能使用传递给 HTML 元素的模态的数据。有没有办法传递模态值并将其转换为 SQL 查询 PHP?
$(function(){
$("body").on('click', '.edit', function (e){
e.preventDefault();
$('#edit').modal('show');
var id = $(this).data('id');
getRow(id);
});
我正在尝试将选定的数据行传递到另一个 PHP 页面,以便它将成为过滤第二个 PHP table.
的参数这是我的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) 我需要的是将数据传递到 table 以便 $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>
所以.. 问题是您必须在同一页面上提交:并在同一页面中解析模态 window 中的 $_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>
希望它有所帮助