简体   繁体   中英

DataTables through a function / PHP

i've currently had some hands on DataTables, i've tried the demo code and manipulated it and it worked fine. Now i already have a table with dynamic data, being pulled using php and mysql through a function, i've added to that function the css and js links in addition to the document.ready function to use the DataTable function on my table. However, after adding the links and ready function, my table is still as the old one even after updating the id/class names.Here's a code snippet:

    include('../session.php');

 echo"<script type='text/javascript' src='https://code.jquery.com/jquery-1.12.4.js'></script>";

 echo"<script type='text/javascript' src='https://cdn.datatables.net/1.10.16/js/jquery.dataTables.min.js'></script>";

 echo "<link href='https://cdn.datatables.net/1.10.16/css/jquery.dataTables.min.css'  rel='stylesheet' type='text/css' />";

echo "<script>
$(document).ready(function() {
    $('#example').DataTable();
} ); </script>
";

Now i do my queries and populate a table with id equal to 'example' and in the end i call this function from another php file.

    $sql = "SELECT wp_users.ID, user_email, display_name, user_registered ,course_progress FROM wp_wpcw_courses, wp_wpcw_user_courses, wp_usermeta, jdashboard, wp_users WHERE  jdashboard.username = '".$this->session."' AND wp_wpcw_courses.course_id=".$cid." AND wp_usermeta.meta_key = 'CouponCode' AND wp_usermeta.meta_value = jdashboard.coupon  AND course_progress >0 AND wp_wpcw_user_courses.user_id = wp_usermeta.user_id AND wp_wpcw_user_courses.user_id= wp_users.ID AND wp_wpcw_user_courses.course_id = wp_wpcw_courses.course_id";
mysqli_set_charset($db,"utf8");
$result = mysqli_query($db, $sql);

And here i go on with other queries and building the table

I'm not really sure what could be the problem, for some reason , the .DataTable function isn't working and therefore not updating my table. Any tips or ideas please ?

Try initialising it using .dataTable() instead of .DataTable() . While the docs specify .DataTable() , the source code specifies .dataTable() as a comment. Here's the relevant screenshot.

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM