Create jQuery DataTable With PHP MySqli Query Results As Source

Hi - I have done this with MS SQL and Joomla but am trying to use Wordpress and MySql. This is a link to the Query tool I am wanting to use – https://datatables.net and this is my code I’m starting with…

I know I’m in the beginning phases but am not sure how to get the array from my PHP code to the JQuery that the datatable needs?

<?php
$dblink = mysqli_connect("website", "user", "pass", "database");
if (mysqli_connect_errno()) {
    echo "Could  not connect to database: Error: ".mysqli_connect_error();
    exit();
}
$sqlquery = "SELECT employee FROM employees LIMIT 10";
if ($result = mysqli_query($dblink, $sqlquery)) {
    while ($row = mysqli_fetch_assoc($result)) {
     $types[] = $row['employee'];
    }
  mysqli_free_result($result);
}
mysqli_close($dblink);

print_r(json_encode(array_values($types)));
?>

echo json_encode($types)

Sponsor our Newsletter | Privacy Policy | Terms of Service