I am new to programming and trying to implement bootstrap modal to display row data from a mysql table into the modal window.
I have tried the solution found on stackoverflow "Pull information from mysql table to bootstrap modal to edit" by link. But could not able to display the particular row with the $row['SFID'].
I can pull table data but when I click the edit button in front of any row it always show the last row id
and doesn't display the data in the input box on the modal to edit the data???.
Here I am till now, Please help me out.
<table class="table table-bordered" width="100%">
<thead>
<tr>
<th>SFID</th>
<th>Company</th>
<th>Product</th>
<th>Product Line</th>
<th>Dealer Class</th>
<th>Status</th>
</tr>
</thead>
<?php
$query = "SELECT * FROM tblcustomer";
$stmt = $db->prepare($query);
$stmt->execute();
foreach ($stmt as $row): ?>
<tr>
<?php $rowID = $row['SFID']; ?>
<td><?php echo $row['SFID']; ?></td>
<td><?php echo $row['CompanyName']; ?></td>
<td><?php echo $row['Product']; ?></td>
<td><?php echo $row['ProductLine']; ?></td>
<td><?php echo $row['DealerClass']; ?></td>
<td><?php echo $row['RequestStatus']; ?></td>
<td style="text-align: center">
<div class="btn-toolbar">
<div class="btn-group">
<a class="btn btn-danger" href="#delModal" data-toggle="modal"><i class="icon-trash icon-white"></i> Delete</a>
<?php echo "<a class='btn update' href='#editModal' data-sfid='".$row['SFID']."' role='button' data-toggle='modal'>Edit</a>"; ?>
</div>
</div>
</td>
</tr>
<?php endforeach; ?>
</table>
<div id="editModal" class="modal hide fade in" style="display: none; ">
<div class="modal-header">
<a class="close" data-dismiss="modal">×</a>
<h3>Edit Customer Details</h3>
</div>
<div>
<form class="contact">
<fieldset>
<div class="modal-body">
<?php echo $row['SFID']; ?>
<ul class="nav nav-list">
<li class="nav-header">SFID</li>
<li><input class="input-xlarge" type="text" name="mysfid" id="mysfid"></li>
<!--<li class="nav-header">Company</li>
<li><input class="input-xlarge" value=" " type="text" name="mycompany"></li>
<li class="nav-header">Dealer Class</li>
<li><input class="input-xlarge" value=" " type="text" name="mydealerclass"></li> -->
</ul>
</div>
</fieldset>
</form>
</div>
<div class="modal-footer">
<button class="btn btn-success" id="submit">Approved</button>
Close
</div>
</div>
<script>
$(document).ready(function(){
$('a.edit').click(function(){
var sfid = $(this).data('sfid');
var company = $(this).data('company');
var dealerclass = $(this).data('dealerclass');
$('#mysfid').val(sfid);
$('#mycompany').val(company);
$('#mydealerclass').val(dealerclass);
});
});
</script>
Thanks for your help.
<table class="table table-bordered" width="100%">
<thead>
<tr>
<th>SFID</th>
<th>Company</th>
<th>Product</th>
<th>Product Line</th>
<th>Dealer Class</th>
<th>Status</th>
</tr>
</thead>
<?php
$query = "SELECT * FROM tblcustomer";
$result = mysql_query($query);
$i=1;
while($row = mysql_fetch_assoc($result))
{
?>
<tr>
<?php $rowID = $row['SFID']; ?>
<td><?php echo $row['SFID']; ?></td>
<td><?php echo $row['CompanyName']; ?></td>
<td><?php echo $row['Product']; ?></td>
<td><?php echo $row['ProductLine']; ?></td>
<td><?php echo $row['DealerClass']; ?></td>
<td><?php echo $row['RequestStatus']; ?></td>
<td style="text-align: center">
<div class="btn-toolbar">
<div class="btn-group">
<a class="btn btn-danger" href="#delModal" data-toggle="modal"><i class="icon-trash icon-white"></i> Delete</a>
<a class="btn update" href="#editModal<?php echo$i?>" data-sfid='"<?php echo $row['SFID'];?>"' data-toggle="modal">Edit</a>
<!--Yor Edit Modal Goes Here-->
<div id="editModal<?php echo $i; ?>" class="modal hide fade in" role="dialog" ria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-header">
<a class="close" data-dismiss="modal">×</a>
<h3>Edit Customer Details</h3>
</div>
<div>
<form class="contact">
<fieldset>
<div class="modal-body">
<?php echo $row['SFID']; ?>
<ul class="nav nav-list">
<li class="nav-header">SFID</li>
<li><input class="input-xlarge" type="text" name="mysfid" id="mysfid"></li>
<!--<li class="nav-header">Company</li>
<li><input class="input-xlarge" value=" " type="text" name="mycompany"></li>
<li class="nav-header">Dealer Class</li>
<li><input class="input-xlarge" value=" " type="text" name="mydealerclass"></li> -->
</ul>
</div>
</fieldset>
</form>
</div>
<div class="modal-footer">
<button class="btn btn-success" id="submit">Approved</button>
Close
</div>
</div>
</div>
</div>
</td>
</tr>
<?php $i++; } ?>
</table>
take $i = 1 above for loop and increament it in each iteration of for loop..so it will take each records
Your Form
<a class='btn update' href='#editModal<?php echo $i;?>' data-sfid='".$row['SFID']."' role='button' data-toggle='modal'>Edit</a>
Modal Window
<div id="editModal<?php echo $i;?>" class="modal hide fade in" style="display: none; ">
That's because you fill the edit modal with the $row data, which by then, is on the last item.
To get data for a specific row, you could create a javascript object/array and then fetch the data by making use of the data-rfid parameter in the "Edit" link. Or you can fetch the row with Ajax for example.
Related
I have a table
I can add 1 question and the added question is spread to all user, but when edited, only 1 row is edited. So if i try to edit question 1 with question id 1 it should also edit the question 1 with id 2.
Is there anyway to solve this?
my table
<table id="tbl_data" class="table table-striped table-bordered zero-configuration">
<thead>
<tr>
<th>No</th>
<th>Question</th>
<th>Question ID</th>
<th>User ID</th>
<th><i class="ft-plus-circle"></i> Add</th>
</tr>
</thead>
<tbody>
<?php $numbering = 1;
foreach ($dataQuestion as $row) : ?>
<tr>
<td><?= $numbering++; ?></td>
<td><?= $row["question"]; ?></td>
<td><?= $row["id"]; ?></td>
<td><?= $row["id_user"]; ?></td>
<td>
<i class="ft-edit"></i>
<i class="ft-trash-2"></i>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
my modal edit
<?php foreach ($dataQuestion as $row) : ?>
<div class="modal fade" id="ModalEdit<?php echo $row['id']; ?>" arta-labelledby="ModalEditLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="ModalEditQuestionLabel">Edit Question</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close" style="outline-style: none;">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<form action="<?= base_url('/displayData/updateQuestion/' . $row["id"]) ?>" method="post">
<?= csrf_field(); ?>
<div class="form-group">
<textarea class="form-control" id="exampleFormControlTextarea1" rows="3" placeholder="Write..." name="question" required><?php echo $row['question']; ?></textarea>
</div>
<button type="submit" class="btn btn-primary btn-block" name="button">Save</button>
</form>
</div>
</div>
</div>
</div>
<?php endforeach; ?>
my controller
public function updateQuestion($id)
{
$dataStored = new questionModel();
$questionModel= $this->questionModel->findAll();
$userModel= $this->userModel->findAll();
foreach ($userModel as $row) {
$data = [
'question' => $this->request->getPost('question')
];
$dataStored->updateData($data, $id);
}
session()->setFlashdata('message', 'Data updated!');
return redirect()->to(base_url('displayData'));
}
I would like to output data in the different tag on call but nothing seems to work, I really dont know what i am doing wrong, could anyone help me?
it displays "Illegal string offset 'patient' in" in all the
PS: I am a beginner to php and mysql. I have edited my code and figured out some errors and I have now noticed that the error is thrown at line 73 on my foreach loop "Warning: Invalid argument supplied for foreach()"
<?php include"../Include/header.php";?>
<?php include"../Include/sidebar.php";?>
<?php
include("../inc/connect.php") ;
$db_connect =mysqli_connect("localhost","root","","clinic_management");
$s="SELECT * FROM addappointment WHERE `app_date` = '".date('Y-m-d')."'";
$query=mysqli_query($db_connect, $s)or die (mysql_error($db_connect));
$row1=mysql_fetch_all($query);
function mysql_fetch_all($query)
{
$temp='';
$all = array();
while ($all[] = mysqli_fetch_assoc($query)) {$temp=$all;}
return $temp;
// print_r($numrows);echo "string"; exit();
}
?>
<div class="content-wrapper">
<section class="content-header">
<h1>
Today's Appointment
<small></small>
</h1>
<ol class="breadcrumb">
<li><i class="fa fa-dashboard"></i> Home</li>
<li class="active">Today's Appointment
</li>
</ol>
</section>
<section class="content">
<!-- Small boxes (Stat box) -->
<div class="row">
<div class="col-md-12">
<div class="box box-primary">
<div class="box-header with-border">
<i class="fa fa-user"></i> <h3 class="box-title"> Today's Appointment</h3>
</div>
<button type="submit" name="submit" class="btn btn-success bg-blue"><i class="fa fa-plus-square"></i> Add Appointment</button><br>
<!-- <td>
<button type="button" class="btn btn-default">Copy</button>
</td> -->
<td>
<button type="button" class="btn btn-default">Excel</button>
</td>
<td>
<button type="button" class="btn btn-default">CSV</button>
</td>
<td>
<button type="button" class="btn btn-default">PDF</button>
</td>
<td>
<button type="button" onclick="window.print();" class="btn btn-default">Print</button>
</td>
<div class="box-body">
<table id="example1" class="table table-bordered table-striped">
<thead>
<tr>
<th> id </th>
<th> Patient </th>
<th> Date </th>
<th> Start Time </th>
<th> End Time </th>
<th> Remark </th>
<th> Option </th>
</tr>
</thead>
<tbody>
<?php
foreach($row1 as $row)
{
$sql1=" SELECT name FROM patientregister WHERE id='".$row['patient']."'";
$write1 =mysqli_query($db_connect, $sql1) or die(mysqli_error($db_connect));
//print_r($sql); exit;
$row2=mysqli_fetch_array($write1)or die (mysqli_error($db_connect));
//print_r($row2); echo $row2['name']; exit;
//echo "$description"; exit();
//print_r($row1); exit;
//echo "$description"; exit();
?> <tr>
<td><?php echo $row['id'];?></td>
<td><?php echo $row['name'];?></td>
<td><?php echo $row['app_date'];?></td>
<td><?php echo $row['starttime'];?></td>
<td><?php echo $row['endtime'];?></td>
<td><?php echo $row['remark'];?></td>
<td><span class="btn btn-danger"><i class="fa fa-trash-o"></i> Delete</span></td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
</div>
</div>
</div>
</section>
</div>
<?php include "../Include/footer.php";?>
If the query doesn't return any rows, mysql_fetch_all() will return an empty string instead of an empty array, because you initialize $temp to a string.
There's no need for the $temp variable in the first place, you can just return $all.
function mysql_fetch_all($query)
{
$all = array();
while ($all[] = mysqli_fetch_assoc($query)) {}
return $all;
}
Also, if you have the MSYQLND driver, there's a built-in mysqli_fetch_all() function, you don't need to write your own.
I have JQUERY datatable in my PHP page in which I have one check box, I want to get the values of all the check boxes checked in that datatable with php code by using
implode(',',$_POST['accessflag']);
But it is showing the values only on the current page. I want to get the values of all checked check boxes in the datatable from all the pages of that particular table .anybody please help me to get this done.
my HTML code is
<div class="row control-container pt-2">
<div class="table-responsive col-md-12">
<div class="row">
<div class="col-md-12" style="text-align:center">
<label style="color:red">
<?php if (isset($_SESSION['SaveMsg'])) { echo $_SESSION['$SaveMsg'];unset($_SESSION['$SaveMsg']);}?>
</label>
</div>
</div>
<table id="moduletable" class="table table-sm table-bordered table-hover table-lightfont display">
<thead class="thead-light">
<tr>
<th><?php echo GetBilingualLabels($_SESSION['$language'],"MODULEACCESS","GRP_DESC"); ?></th>
<th><?php echo GetBilingualLabels($_SESSION['$language'],"MODULEACCESS","MODULE_NAME"); ?></th>
<th><?php echo GetBilingualLabels($_SESSION['$language'],"MODULEACCESS","GMA_ACCESS_FLAG"); ?></th>
<th><?php echo GetBilingualLabels($_SESSION['$language'],"MODULEACCESS","OPTIONS"); ?></th>
</tr>
</thead>
<tbody>
<?php
if(isset($_SESSION['$nextset'])){
$limit=$_SESSION['$nextset'];}
else{$limit=0;}
if ($_SESSION['$language']="E") {
$groupdata=SelectData("group_module_access,user_group,modules","gma_id,gma_grp_id,grp_desc,gma_module_id,module_name,gma_access_flag","gma_grp_id=grp_id and gma_module_id=module_id","gma_grp_id,gma_id LIMIT ".$limit.",50");
}
else {
$groupdata=SelectData("group_module_access,user_group,modules","gma_id,gma_grp_id,grp_bldesc as grp_desc,gma_module_id,module_blname as module_name,gma_access_flag","gma_grp_id=grp_id and gma_module_id=module_id","gma_grp_id,gma_id LIMIT ".$limit.",50");
}
foreach ($groupdata as $groupdatalist) {?>
<tr>
<td><?php echo $groupdatalist["grp_desc"];?></td>
<td><?php echo $groupdatalist["module_name"];?></td>
<?php if($groupdatalist["gma_access_flag"]=="N"):?>
<td style="text-align:right;width:10px;"><input type="checkbox" name="accessflag[]" id="accessflag"
value="<?php echo "{$groupdatalist['gma_id']}"?>"/> </td>
<?php else:?>
<td style="text-align:right;width:10px;"><input type="checkbox" checked name="accessflag[]" id="accessflag" width="10px"
value="<?php echo "{$groupdatalist['gma_id']}"?>"/> </td>
<?php endif;?>
<!--<td style="display:none;"><//?php echo $groupdatalist["gma_grp_id"];?></td>
<td style="display:none;"><//?php echo $groupdatalist["gma_module_id"];?></td>
<td style="display:none;"><input type="text" name="gmaid" id="gmaid" value="<//?php echo $groupdatalist["gma_id"];?>"></td>-->
<td>
<?php if($groupdatalist["gma_access_flag"]=="N"):?>
<a href="#" class="btn btn-light btn-sm pt-0 shadow-none"
data-toggle="tooltip" title="<?php echo GetBilingualLabels($_SESSION['$language'],"MODULEACCESS","MENUPERMISSION");?>">
<i class="fa fa-pencil-square-o"></i>
</a>
<?php else:?>
<a href="group_action.php?gmagrpid=<?php echo $groupdatalist['gma_grp_id']?>&gmamoduleid=<?php echo $groupdatalist['gma_module_id']?>&page=MenuPermission&gmagrpdesc=<?php echo $groupdatalist['grp_desc']?>&gmamodulename=<?php echo $groupdatalist['module_name']?>" class="btn btn-light btn-sm pt-0 shadow-none"
data-toggle="tooltip" title="<?php echo GetBilingualLabels($_SESSION['$language'],"MODULEACCESS","MENUPERMISSION");?>">
<i class="fa fa-pencil-square-o"></i>
</a>
<?php endif;?>
</td>
</tr>
<?php } ?>
</tbody>
</table>
<div class="row">
<div class="col-md-12 text-right">
<button type="submit" name="updmodaccess" formnovalidate class="btn nc btn-primary btn-rounded">
<i class="fa fa-save"></i>
<?php echo GetBilingualLabels($_SESSION['$language'],"BUTTON","SAVE"); ?>
</button>
</div>
</div>
</div>
</div>
PHP code on updmodaccess button is
if (isset($_POST['updmodaccess'])) {
$keytoupdate=implode(',',$_POST['accessflag']);
$table="group_module_access"; $data=array("gma_access_flag"=>"Y", "gma_upd_dt"=>GetDateTime($_SESSION['$TimeZone']), "gma_upd_uid"=>"{$_SESSION['$userid']}");
UpdateData($table,$data,"gma_id in (".$keytoupdate.")",$Message,$flg);
$data=array("gma_access_flag"=>"N", "gma_upd_dt"=>GetDateTime($_SESSION['$TimeZone']), "gma_upd_uid"=>"{$_SESSION['$userid']}");
UpdateData($table,$data,"gma_id not in (".$keytoupdate.")",$Message,$flag);
}
you can try the following code. I hope it helps.
you need to get these values using ajax and then need to send this value to php using an ajax.
$(document).ready(function(){
var data = new Object();
var table = $('#addUsersToAboTable').DataTable();
$('#addUsersToAboTable').on('change', ':checkbox', function () {
data[table.row($(this).parents('tr').get(0)).index()] = this.checked;
});
$('#getDataBtn').on('click',function(){
console.log(data);
});
});
Here you can see the demo script as well jQuery Datatables, How to get all selected checkboxes from EVERY page
I have designed one page consisting of one modal window which is opening with tag.
I want to pass some parameters to modal window which i will be using to populate table data based on the parameter value.It is working with one parameter but not working with another parameter.
Following is the HTML to open modal window......
<table id="MyTable1" class="table table-sm table-striped table-lightfont paginated">
<thead class="thead-light">
<tr>
<th><?php echo GetBilingualLabels($_SESSION['$language'],"MODULEACCESS","GRP_DESC"); ?></th>
<th><?php echo GetBilingualLabels($_SESSION['$language'],"MODULEACCESS","MODULE_NAME"); ?></th>
<th><?php echo GetBilingualLabels($_SESSION['$language'],"MODULEACCESS","GMA_ACCESS_FLAG"); ?></th>
<th><?php echo GetBilingualLabels($_SESSION['$language'],"MODULEACCESS","OPTIONS"); ?></th>
</tr>
</thead>
<tbody>
<?php
if ($_SESSION['$language']="E") {
$groupdata=SelectData("group_module_access,user_group,modules","gma_id,gma_grp_id,grp_desc,gma_module_id,module_name,gma_access_flag","gma_grp_id=grp_id and gma_module_id=module_id","gma_grp_id,gma_id");
}
else {
$groupdata=SelectData("group_module_access,user_group,modules","gma_id,gma_grp_id,grp_bldesc as grp_desc,gma_module_id,module_blname as module_name,gma_access_flag","gma_grp_id=grp_id and gma_module_id=module_id","gma_grp_id,gma_id");
}
foreach ($groupdata as $groupdatalist) {
//$allids[]=$groupdatalist["gma_id"]; ?>
<tr>
<td><?php echo $groupdatalist["grp_desc"];?></td>
<td><?php echo $groupdatalist["module_name"];?></td>
<?php if($groupdatalist["gma_access_flag"]=="N"):?>
<td style="text-align:right;width:10px;"><input type="checkbox" name="accessflag[]" id="accessflag"
value="<?php echo "{$groupdatalist['gma_id']}"?>"/> </td>
<?php else:?>
<td style="text-align:right;width:10px;"><input type="checkbox" checked name="accessflag[]" id="accessflag" width="10px"
value="<?php echo "{$groupdatalist['gma_id']}"?>"/> </td>
<?php endif;?>
<td style="display:none;"><?php echo $groupdatalist["gma_grp_id"];?></td>
<td style="display:none;"><?php echo $groupdatalist["gma_module_id"];?></td>
<td style="display:none;"><input type="text" name="gmaid" id="gmaid" value="<?php echo $groupdatalist["gma_id"];?>"></td>
<!--<td style="display:none"><input type="text" name="allids[]" value="<//?php echo "{$groupdatalist['gma_id']}"?>"/></td>-->
<td>
<span data-toggle="modal" data-target="#myModal-<?php echo $groupdatalist['gma_id'];?>">
<a href="#" class="btn btn-light btn-sm shadow-none"
data-toggle="tooltip" title="<?php echo GetBilingualLabels($_SESSION['$language'],"MODULEACCESS","MENUPERMISSION");?>">
<i class="fa fa-pencil-square-o"></i>
</a>
</span>
</td>
</tr>
<?php } ?>
</tbody>
</table>
Here is the modal window HTML.....
<div id="myModal-<?php echo $groupdatalist['gma_grp_id'];?>" class="modal show fade" data-backdrop="static">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<div class="modal-header">
<h6 class="modal-title">Menu List</h6>
</div>
<div class="modal-body">
<div class="control-container" style="padding:10px;">
<div class="row">
<div class="col-md-12" style="text-align:center">
<label style="color:red">
<?php //session_start();
if (!empty($_SESSION['$SaveMsg'])) { echo $_SESSION['$SaveMsg']; }
unset($_SESSION['$SaveMsg']);
?>
</label>
</div>
</div>
<div class="row">
<div class="col-md-4">
<label><?php echo GetBilingualLabels($_SESSION['$language'],"MODULEACCESS","GRP_DESC"); ?>
</label>
</div>
<div class="col-md-8">
<input class="text-control" type="text" name="grpid" id="grpid"
value="" readonly required maxlength="50" style="width:100%;display:none;" autofocus />
<input class="text-control" type="text" name="grpname" id="grpname"
value="" readonly required maxlength="50" style="width:100%" autofocus />
</div>
</div>
<div class="row">
<div class="col-md-4">
<label><?php echo GetBilingualLabels($_SESSION['$language'],"MODULEACCESS","MODULE_NAME"); ?>
</label>
</div>
<div class="col-md-8">
<input class="text-control" type="text" name="moduleid" id="moduleid"
value="" readonly required maxlength="50" style="width:100%;display:none" autofocus />
<input class="text-control" type="text" name="modulename" id="modulename"
value="" readonly required maxlength="50" style="width:100%" autofocus />
</div>
</div>
<?php $gmaid= "<script>document.writeln(gmaid);</script>";
echo $gmaid;?>
<!--table starts here -->
<table id="MyTable2" class="table table-sm table-striped table-lightfont paginated">
<thead class="thead-light">
<tr>
<th><?php echo GetBilingualLabels($_SESSION['$language'],"MENUACCESS","MENUNAME"); ?></th>
<!--<th><//?php echo GetBilingualLabels($_SESSION['$language'],"MODULEACCESS","MODULE_NAME"); ?></th>-->
<th><?php echo GetBilingualLabels($_SESSION['$language'],"MENUACCESS","ACCESS_FLAG"); ?></th>
<!--<th><//?php echo GetBilingualLabels($_SESSION['$language'],"MENUACCESS","OPTIONS"); ?></th>-->
</tr>
</thead>
<tbody>
</table>
<!-- table ends here -->
<div class="modal-footer">
<button type="button" class="btn btn-danger" data-dismiss="modal">
<i class="fa fa-close"></i>
<?php echo GetBilingualLabels($_SESSION['$language'],"BUTTON","CANCEL"); ?>
</button>
<button type="submit" name="updmenuperm" formnovalidate class="btn btn-primary"> <!--onclick="DispMsg(<//?php echo "'".$_SESSION['AlertMsg']."'";?>)"-->
<i class="fa fa-save"></i>
<?php echo GetBilingualLabels($_SESSION['$language'],"BUTTON","SAVE"); ?>
</button>
</div>
</div>
</div>
</div>
</div>
Above code is working perfectly but if i am using another value as parameter it is not opening the modal window at all.
for ex. if i am using $groupdatalist['gma_id'] which is integer value, it is not opening modal window.
Multiple issues here.
First a </div> is missing at the end.
Then you are defining $groupdatalist in a foreach, but trying to use it outside the loop:
<div id="myModal-<?php echo $groupdatalist['gma_grp_id'];?>" class="modal show fade" data-backdrop="static">
If you want one modal per <td> you have to move your modal into the foreach loop.
Finally, you call the modal using $groupdatalist['gma_id']
<span data-toggle="modal" data-target="#myModal-<?php echo $groupdatalist['gma_id'];?>">
but the modal ID is define using a different variable : $groupdatalist['gma_grp_id']:
<div id="myModal-<?php echo $groupdatalist['gma_grp_id'];?>"
I have a dynamic table with edit and delete button. I was able to passed the variable $parid to modal. However, it's not fetching the data into the modal using the $parid. I cannot figure out what have i missed out. I just want to display the corresponding data using mysql code WHERE parid='$parid'. The value of $parid is passed to the <input type="text" name="parid" id="parid">. Here's my sample code:
<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>
You have lost track of the scope and timing of your PHP and jQuery code. The jQuery part:
<script>
$(document).on("click", ".btndel", function () {
var parid = $(this).data('id');
$(".modal-body #parid").val( parid );
$('#delpar').modal('show');
});
</script>
runs on the users browser after they have viewed what came from the server. The PHP code inside your "Delete Par Modal" runs on the server before the jQuery even gets to the browser.
In your jQuery you need to add an AJAX call to get the data you need FROM THE SERVER (where your query then runs and returns the data) in real time. Then "on success" the AJAX call should populate the Modal fields.