I just started learning DataTable.js and I've got one doubt regarding server-side processing in DataTable.js, that is, how can I load the table in server-side processing?
I'm posting my code here so it would be easy to understand
table.html
<table id="empTable">
<thead>
<th>First Name</th>
<th>Last Name</th>
<th>Email</th>
<th>Phone Number</th>
</thead>
</table>
script.js
<script type="text/javascript">
var empTable;
$(document).ready(function(){
empTable = $("#empTable").dataTable({
'processing':true,
'serverside':true,
'ajax': 'fetchRecord.php'
});
});
</script>
fetchRecord.php
<?php
$conn = new mysqli('localhost','root','','example');
if($conn->connect_error) die("Could not connect".$conn->connect_error);
$fetchQuery = "SELECT firstname, lastname, email, phonenumber FROM employee";
$output = array('data' => array());
$result = $conn->query($fetch);
if($result->num_rows > 0){
while($row = $result->fetch_assco()){
$output['data'][] = $row;
}
}
$conn->close();
echo json_encode($output);
?>
Please tell me what's wrong with this code and how can I fetch data from php page and load it in DataTable?
Apologies for any mistakes.
Thank you in advance