What I want to do is, I have fetched data tables using JQUERY, Ajax, PHP after that selected multiple check box in the table, those selected rows of data I want to store in new database table on submit button
I don't know how to do it, I googled but there is I Don't find any such solution for this.
HTML code here
<label for="fname">insert number for select multiple check box</label>
<input type="number" id="selectcheckbox" name="selectcheckbox">
<table class="table table-striped table-bordered" id="tbl">
<thead>
<tr>
<th>SELECT check-box</th>
<th>QUALITY REPORT NO</th>
<th>UID NO </th>
<th>ITEM CODE </th>
<th>DESCRIPTION</th>
<th>H.NO </th>
<th>Qty</th>
<th>SELECTED QTY </th>
<th>NOTE</th>
<th>LOCATION</th>
<th>SELECTED QTY hidden</th>
<th>NOTE hidden</th>
<th>LOCATION hidden</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
<button type="button" class="btn btn-primary" name="submitdata" id="submitdata">submit data</button>
java-script here
<script>
$(document).ready(
function()
{
var table = $('#tbl').DataTable({
"columnDefs":
[{
orderable: false,
className: 'select-checkbox',
targets: 0
}],
destroy:true,
"fnRowCallback" :
function(nRow, aData, iDisplayIndex)
{
$("td:first", nRow).html(iDisplayIndex +1);
return nRow;
},
'select':
{
style: 'multi',
selector:'td:nth-child(1)'
},
'order': [[ 1, 'asc' ]],
});
$.ajax({
type:"POST",
url:"fetch_data.php",
data:'item_code_no='+item_code_no,
success: function(data)
{
if(data['error'] == '0')
{
console.log(data);
//set Finish Data
table.clear().draw();
for(i = 0; i < data['chemical_date'].length; i++)
{
table.row.add([
data['chemical_date'][i]['mqr_id'],
data['chemical_date'][i]['mqr_id'],
data['chemical_date'][i]['uid'],
data['chemical_date'][i]['item_code'],
data['chemical_date'][i]['description'],
data['chemical_date'][i]['h_no'],
data['chemical_date'][i]['qty'],
"<input type='text' value='' class='form-control' id='selectedqty"+i+"' onkeyup='sqty(this.id);' name='selectedqty"+i+"'/>",
"<input type='text' value='' class='form-control ' id='note"+i+"' name='note"+i+"' />",
"<input type='text' value='' class='form-control ' id='location"+i+"' name='location"+i+"' />",
'',
'',
''
]).draw(false);
}
}
}
})
});
</script>
<script>
// select check box script
$("#selectcheckbox").on("change", function(){
//remove selected class
$("#example tr").removeClass("selected")
for (let i = 0; i < $(this).val(); i++)
{
//check if td there ...
if ($("#tbl td.select-checkbox:eq(" + i + ")").length > 0)
{
//add selected class..
$("#tbl td.select-checkbox:eq(" + i + ")").closest("tr").addClass("selected") //try with `.click()` as well..
}
}
})
</script>
below code is fetched data from Database using PHP
fetch_data.php
<?php
header('Content-Type: application/json');
$response = array();
$response = array();
if($_SERVER['REQUEST_METHOD']=='POST')
{
extract($_POST);
//Top data
$data = array();
$obj = array();
$sql = "SELECT DISTINCT mqr.sr_no as mqr_id,mi.item_code,mqrpd.uid,mqrpd.qty,mqrpd.h_no,mqrpd.htc_no,md.description
FROM table1 mqr,table2 mqrpd,table3 mi,table4 md
WHERE mqr.item_id_fk=$item_code_no and mqr.id=mqrpd.quality_report_id_fk and mqr.item_id_fk=mi.id and mi.drawing_id_fk=md.id";
$result = mysqli_query($db, $sql);
$chemical = array();
while($row = mysqli_fetch_assoc($result))
{
//Finish Data
$row1 = array();
$row1['mqr_id'] = $row['mqr_id'];
$row1['item_code'] = $row['item_code'];
$row1['uid'] = $row['uid'];
$row1['qty'] = $row['qty'];
$row1['h_no'] = $row['h_no'];
$row1['htc_no'] = $row['htc_no'];
$row1['description'] = $row['description'];
array_push($chemical, $row1);
//Stock Data
}
$response['chemical_date'] = $chemical;
//Process Data
$response['error'] = "0";
}
else
$response['error'] = "1";
echo json_encode($response);
?>