select data with datatables plugin
Hello,
I want to show data with the DataTable plugin. I use a mysql database for save the data.
But now I get the error: No data found. But I want select the data from the php file.
My question is: How can I select the data from the mysql with the DataTable plugin?
Can someone help me what is going wrong?
thanks in advance
index.php:
- <!DOCTYPE html>
- <html>
- <title></title>
- <head>
- <link rel="stylesheet" type="text/css" href="css/jquery.dataTables.css">
- <script src="js/jquery.js"></script>
- <script src="js/jquery.dataTables.js"></script>
- <script>
- $(document).ready(function() {
- var dataTable = $('#bijdrager-grid').DataTable( {
- "processing": true,
- "serverSide": true,
- "ajax":{
- url :"data.php", // json datasource
- type: "post", // method , by default get
- error: function(){ // error handling
- $(".bijdrager-grid-error").html("");
- $("#bijdrager-grid").append('<tbody class="bijdrager-grid-error"><tr><th colspan="3">No data found</th></tr></tbody>');
- //$("#bijdrager-grid").html(html).show();
- $("#bijdrager-grid_processing").css("display","none");
-
- }
- }
- } );
- } );
- </script>
- <style>
- div.container {
- margin: 0 auto;
- max-width:760px;
- }
- div.header {
- margin: 100px auto;
- line-height:30px;
- max-width:760px;
- }
- body {
- background: #f7f7f7;
- color: #333;
- font: 90%/1.45em "Helvetica Neue",HelveticaNeue,Verdana,Arial,Helvetica,sans-serif;
- }
- </style>
- </head>
- <body>
- <div class="header"></div>
- <div class="container">
- <table id="bijdrager-grid" cellpadding="0" cellspacing="0" border="0" class="display" width="100%">
- <thead>
- <tr>
- <th>Voornaam</th>
- <th>Tussenv.</th>
- <th>Achternaam</th>
- <th>titel</th>
- <th>Jaar</th>
- </tr>
- </thead>
- </table>
- </div>
- </body>
- </html>
data.php:
- <?php
- include "includes/mysqli_connect.php";
- $query = "SELECT v_naam, t_voeg, a_naam, titel, jaar FROM data b, tblfoto_info f WHERE b.bijdr_id = f.bijdr_id";
- $result = mysqli_query($dbcon, $query) or die(mysqli_error());
- echo "<table id="bijdrager-grid">";
- echo "<tr>";
- echo "<th>Voornaam</th>";
- echo "<th>Tussenvoegsel</th>";
- echo "<th>achternaam</th>";
- echo "<th>Titel</th>";
- echo "<th>Jaar</th>";
- echo "</tr>";
- while ($record = mysqli_fetch_assoc($result)) {
-
- $v_naam = $record['v_naam'];
- $t_naam = $record['t_voeg'];
- $achternaam = $record['a_naam'];
- $titel = $record['titel'];
- $jaar = $record['jaar'];
-
- echo "<tr>";
- echo "<td> $v_naam </td> <td>$t_naam</td> <td>$achternaam</td> <td>$titel</td> <td>$jaar</td> ";
- echo "</tr>";
- }
- echo "</table>";
- ?>