I have these two tables, namely table1.php and table2.php
I can pass the data to a modal using this script, this script is in table1.php, and it can pass data into table2.php via modal, my concern now is how will I pass the data directly into table2.php's SQL Query? Because of the way that it is, I can only use the data passed into a modal for HTML elements. Is there a way to pass the modal value and convert it into a SQL Query for PHP?
$(function(){
$("body").on('click', '.edit', function (e){
e.preventDefault();
$('#edit').modal('show');
var id = $(this).data('id');
getRow(id);
});
I'm trying to pass the selected data row into another PHP page so that it will become the parameter for filtering the second PHP table.
This is my 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>
And this will be my 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>
The problem is that table2.php cannot receive the $_POST, what seems to be the problem here?
EDIT: This is my modal (table2.php) What I need is for the data to be passed into the table so that $id=$_POST['seriesno'];
will work.
<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>