Lebza Seeko

Lebza Seeko

  • NA
  • 4
  • 470

trying to display data in dataTables table

Jul 22 2020 6:23 AM
i have a data.php code which is as follows:
 
and my html projects.php
  1. <?php include("db_connection.php")?>  
  2. <?php include("Main_Dashboard.php")?>  
  3. <!DOCTYPE html>  
  4. <html lang="en">  
  5. <head>  
  6. <?php include("partials/head.php")?>  
  7. <meta charset="UTF-8">  
  8. <meta name="viewport" content="width=device-width, initial-scale=1.0">  
  9. <title>Project Information Area</title>  
  10. </head>  
  11. <body>  
  12. <?php include("partials/add_button.php")?>  
  13. <hr>  
  14.   
  15. <table id="#example" class="table-striped table-bordered" style="width:100%">  
  16. <thead>  
  17. <tr>  
  18. <th>Municipality</th>  
  19. <th>Contact Person</th>  
  20. <th>Email</th>  
  21. <th>Phone</th>  
  22. <th>Designation</th>  
  23. <th>Department</th>  
  24. <th>Project Data</th>  
  25. </tr>  
  26. </thead>  
  27.   
  28. </script>  
  29. </tbody>  
  30. </table>  
  31. <script type="text/javascript">  
  32. $(document).ready(function() {  
  33. $('#example').DataTable( {  
  34. "ajax" :{  
  35. "url":"data.php",  
  36. "dataSrc" : " "  
  37. },  
  38. "columns" : [  
  39. {"data":"Municipality"},  
  40. {"data":"Contact Person"},  
  41. {"data":"Email"},  
  42. {"data":"Phone"},  
  43. {"data":"Designation"},  
  44. {"data":"Deapartment"},  
  45. {"data":"ProjectData"},  
  46. ]  
  47. });  
  48. });  
  49. <?php include("partials/table_script.php")?>  
  50. <?php include("partials/js_script.php")?>  
  51. </body>  
  52. </html>  
  53. <?php  
  54. $con = mysqli_connect("localhost""root""""solid");  
  55. $result = mysqli_query($con"SELECT municipality, contact_person, email, phone, designation, department, project_data FROM projects");  
  56. // Add all records into an array  
  57. $rowsarray();  
  58. while($row = mysqli_fetch_array($result))  
  59. {  
  60. $rows [] = $row;  
  61. }  
  62. echo json_encode($rows);  
  63. ?>  

Answers (1)