I have a problem getting the data in JSON format via the data.php file. When I try see JSON I got this: "{"draw":0,"recordsTotal":null,"recordsFiltered":120,"data":[]}"
but needs the php script to retrieve data from the table all entries for the column date, name, id like datatables AJAX instructions . When doing this using the local XAMPP server, the script retrieves the entries from the mysql table and the data is displayed as a table using datatables.
Here is my PHP code
$connect = new PDO("mysql:host=localhost;dbname=abc", "root", "PASSWORD");
$query = "SELECT * FROM abc_result ";
if(isset($_POST["search"]["value"]))
{
$query .= '
WHERE DATE LIKE "%'.$_POST["search"]["value"].'%"
OR NAME LIKE "%'.$_POST["search"]["value"].'%"
OR ID LIKE "%'.$_POST["search"]["value"].'%"
';
}
if(isset($_POST['DATE']))
{
$query .= 'ORDER BY '.$column[$_POST['DATE']['0']['column']].' '.$_POST['DATE']['0']['dir'].' ';
}
else
{
$query .= 'ORDER BY ID DESC ';
}
$query1 = '';
if($_POST['length'] != -1)
{
$query1 = 'LIMIT ' . $_POST['start'] . ', ' . $_POST['length'];
}
$statement = $connect->prepare($query);
$statement->execute();
$number_filter_row = $statement->rowCount();
$result = $connect->query($query . $query1);
$data = array();
foreach($result as $row)
{
$sub_array = array();
$sub_array[] = $row['DATE'];
$sub_array[] = $row['NAME'];
$sub_array[] = $row['ID'];
$data[] = $sub_array;
}
function count_all_data($connect)
{
$query = "SELECT COUNT(*) FROM abc_result";
$statement = $connect->prepare($query);
$statement->execute();
$result = $statement->fetchColumn();
return $result;
}
$output = array(
"draw" => intval($_POST["draw"]),
"recordsTotal" => count_all_data($connect),
"recordsFiltered" => $number_filter_row,
"data" => $data
);
echo json_encode($output);
I'm trying to retrieve data from my mysql database and display it using datatables. locally I've been able to do it but I'd like to do it on a NAS (QNAP) so that when I go to a website the table would be visible by anyone who visits it. To do this, I installed MariaDB 5 and PHPmyAdmin. I was able to connect to the database but the php code does not display the data as I would like it to