I was able to get their corresponding ID from the array by adding attribute to my button, I was wondering if how can make popped up my modal by clicking whole table row instead of clicking the Edit button
My functional modal by clicking edit button:
<!--script for fetching data from db-->
<script>
$(document).ready(function(){
var dataTable=$('#example').DataTable({
"processing": true,
"serverSide":true,
"ajax":{
url:"fetch.php",
type:"post"
}
});
});
</script>
<!--script js for get edit data-->
<script>
$(document).on('click','#getEdit',function(e){
e.preventDefault();
var per_id=$(this).data('id');
//alert(per_id);
$('#content-data').html('');
$.ajax({
url:'editdata.php',
type:'POST',
data:'id='+per_id,
dataType:'html'
}).done(function(data){
$('#content-data').html('');
$('#content-data').html(data);
}).fial(function(){
$('#content-data').html('<p>Error</p>');
});
});
</script>
heres my fetch.php
$query=mysqli_query($con,$sql);
$data=array();
while($row=mysqli_fetch_array($query)){
$subdata=array();
$subdata[]=$row[0]; //id
$subdata[]=$row[1]; //name
$subdata[]=$row[2]; //salary
$subdata[]=$row[3]; //age //create event on click in button edit in cell datatable for display modal dialog $row[0] is id in table on database
$subdata[]='<button type="button" id="getEdit" class="btn btn-primary btn-xs" data-toggle="modal" data-target="#myModal" data-id="'.$row[0].'"><i class="glyphicon glyphicon-pencil"> </i>Edit</button>
<button type="button" class="btn btn-danger btn-xs"><i class="glyphicon glyphicon-trash"> </i>Delete</button>';
$data[]=$subdata;
}
heres my editdata.php
if(isset($_REQUEST['id'])){
$id=intval($_REQUEST['id']);
$sql="select * from pcfields_data WHERE pcfield_id=$id";
$run_sql=mysqli_query($con,$sql);
while($row=mysqli_fetch_array($run_sql)){
$per_id=$row[0];
$per_name=$row[1];
$per_salay=$row[2];
$per_age=$row[3];
}