i have used dataTable() function for getting my table data but it is not working?
i have used dataTable() function for getting my table data but it is not working?
i have given my whole code please is there anyone who can tell me where is the problem
index.php:
<!DOCTYPE html>
<html>
<head>
<title>dashboard</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
<link rel="stylesheet" href="//cdn.datatables.net/1.10.20/css/jquery.dataTables.min.css">
</head>
<body>
<?php
include 'header.php';
Patient entry form
<
script>
getall();
function getall() {
$('tbl_patient').dataTable().fnDestroy();
$.ajax({
url: "php/all_patient.php",
type: "GET",
datatype: "JSON",
success: function(data) {
$('#tbl_patient').html(data);
$('#tbl_patient').dataTable({
"aaData" : data,
"scrollX" : true,
"aoColumns" : [
{"sTitle" : "Patient No", "mData" : "patientno"},
{"sTitle" : "Patient Name", "mData" : "name"},
{"sTitle" : "Phone", "mData" : "phone"},
{"sTitle" : "Address", "mData" : "address"}
]
});
}
})
}
all_patient.php:
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "hms";
$con = new mysqli( $servername, $username, $password, $dbname);
if($con->connect_error){
die("connection failed". $con->connect_error);
}
$stmt = $con->prepare("select patientno,name,phone,address from patient order by patientno");
$stmt->bind_result($patientno, $name, $phone, $address);
if ($stmt->execute()) {
while ($stmt->fetch()) {
$output[] = array("patientno" => $patientno,"name"=> $name,"phone" => $phone,"address" => $address);
}
echo json_encode($output);
}
$stmt->close();
<?php
>
?>
Answers
We're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.
Cheers,
Colin