# Create jQuery DataTable With PHP MySqli Query Results As Source

**URL:** <https://www.phphelp.com/t/create-jquery-datatable-with-php-mysqli-query-results-as-source/29592>\
**Category:** Help with WordPress\
**Created:** [July 29, 2019, 12:58am UTC](https://www.phphelp.com/t/create-jquery-datatable-with-php-mysqli-query-results-as-source/29592 "2019-07-29T00:58:20Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![miketheknight2016](https://www.phphelp.com/letter_avatar_proxy/v4/letter/m/eb8c5e/32.png) [@miketheknight2016](https://www.phphelp.com/u/miketheknight2016)\
**Post date:** [July 29, 2019, 12:58am UTC](https://www.phphelp.com/t/create-jquery-datatable-with-php-mysqli-query-results-as-source/29592/1 "2019-07-29T00:58:20Z")

</div>

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](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?

```auto
<?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)));
?>

```

---

<div class="post-metadata">

**Author:** ![astonecipher](https://www.phphelp.com/user_avatar/www.phphelp.com/astonecipher/32/2797_2.png) [@astonecipher](https://www.phphelp.com/u/astonecipher)\
**Post date:** [July 30, 2019, 11:36am UTC](https://www.phphelp.com/t/create-jquery-datatable-with-php-mysqli-query-results-as-source/29592/2 "2019-07-30T11:36:49Z")

</div>

echo json\_encode($types)
