I've Google and found answers for the "DataTables warning (table id = 'directory'): Requested unknown parameter '0' from the data source for row 0" error....but none of them seem to work and I cannot figure this out.
Until this week I had never heard of JSON or Datatables, but I've been tasked with converting a ColdFusion script that uses them to PHP.
Here is my PHP script that creates the JSON data:
and here is the page that calls the list:
When I run the page I get the error but it does show the correct number of records (but shows no records) so something is working.
Can someone tell me what I am doing wrong and how to make it work?
</script>
When I run the page I get the error but it does show the correct number of records (but shows no records) so something is working.
Can someone tell me what I am doing wrong?
Until this week I had never heard of JSON or Datatables, but I've been tasked with converting a ColdFusion script that uses them to PHP.
Here is my PHP script that creates the JSON data:
$ldap_password = 'pass'; $ldap_username = 'user'; $ldap_connection = ldap_connect('college.edu'); if (FALSE === $ldap_connection){ // Uh-oh, something is wrong... } ldap_set_option($ldap_connection, LDAP_OPT_PROTOCOL_VERSION, 3) or die('Unable to set LDAP protocol version'); ldap_set_option($ldap_connection, LDAP_OPT_REFERRALS, 0); // We need this for doing an LDAP search. if (TRUE === ldap_bind($ldap_connection, $ldap_username, $ldap_password)){ $ldap_base_dn = 'OU=Users,DC=college,DC=edu'; $search_filter = "(&(objectCategory=Person)(objectClass=User)(employeeId=*)(mail=*)(|(memberOf=CN=ActiveGroup - Employees,OU=ActiveGroups,DC=college,DC=edu)(memberOf=CN=ActiveGroup - Students,OU=ActiveGroups,DC=college,DC=edu)))"; $attributes = array(); $attributes[] = 'sn'; $attributes[] = 'givenname'; $attributes[] = 'mail'; $attributes[] = 'samaccountname'; $attributes[] = 'department'; $attributes[] = 'title'; $attributes[] = 'physicaldeliveryofficename'; $attributes[] = 'telephonenumber'; $result = ldap_search($ldap_connection, $ldap_base_dn, $search_filter, $attributes); if (FALSE !== $result){ $entries = ldap_get_entries($ldap_connection, $result); for ($x=0; $x<$entries['count']; $x++){ if (!empty($entries[$x]['givenname'][0]) && !empty($entries[$x]['mail'][0]) && !empty($entries[$x]['samaccountname'][0]) && !empty($entries[$x]['sn'][0]) && '' !== $entries[$x]['sn'][0]){ $ad_users[strtoupper(trim($entries[$x]['samaccountname'][0]))] = array('email' => strtolower(trim($entries[$x]['mail'][0])),'first_name' => trim($entries[$x]['givenname'][0]),'last_name' => trim($entries[$x]['sn'][0])); if (empty($entries[$x]['sn'][0])) { $sn = ""; }else{ $sn = ($entries[$x]['sn'][0]); } if (empty($entries[$x]['givenname'][0])) { $givenname = ""; }else{ $givenname = ($entries[$x]['givenname'][0]); } if (empty($entries[$x]['samaccountname'][0])) { $samaccountname = ""; }else{ $samaccountname = ($entries[$x]['samaccountname'][0]); } if (empty($entries[$x]['department'][0])) { $department = ""; }else{ $department = ($entries[$x]['department'][0]); } if (empty($entries[$x]['title'][0])) { $title = ""; }else{ $title = ($entries[$x]['title'][0]); } if (empty($entries[$x]['telephonenumber'][0])) { $telephonenumber = ""; }else{ $telephonenumber = ($entries[$x]['telephonenumber'][0]); } if (empty($entries[$x]['physicaldeliveryofficename'][0])) { $physicaldeliveryofficename = ""; }else{ $physicaldeliveryofficename = ($entries[$x]['physicaldeliveryofficename'][0]); } if (empty($entries[$x]['mail'][0])) { $mail = ""; }else{ $mail = ($entries[$x]['mail'][0]); } $array["aaData"][] = array( 'sn' => $sn, 'givenname' => $givenname, 'samaccountname' => $samaccountname, 'telephonenumber' => $telephonenumber, 'physicaldeliveryofficename' => $physicaldeliveryofficename, 'department' => $department, 'title' => $title ); } } echo json_encode($array); } ldap_unbind($ldap_connection); // Clean up after ourselves. }
and here is the page that calls the list:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <title>Campus Directory</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <link rel="stylesheet" href="//ajax.googleapis.com/ajax/libs/jqueryui/1.8.19/themes/base/jquery-ui.css" type="text/css"> <link rel="stylesheet" href="//ajax.googleapis.com/ajax/libs/jqueryui/1.8.19/themes/smoothness/jquery-ui.css" type="text/css"> <script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script> <script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jqueryui/1.8.19/jquery-ui.min.js"></script> <link rel="stylesheet" href="DataTables-1.8.1/media/css/demo_table.css" type="text/css"> <script type="text/javascript" src="DataTables-1.8.1/media/js/jquery.dataTables.min.js"></script> </head> <body > <style type="text/css"> #directory { border:1px solid #ccccff; margin-bottom:10px; margin-top:10px; width:100%; } #directory thead th, #directory tbody td { font-size:11px; padding:5px; white-space:nowrap; } #directory thead th { padding-right:20px; text-align:left; } #directory tbody td.dept { white-space:normal; } #directory tbody td.title { white-space:normal; } .dataTables_filter input { width:200px; } </style> <div style="padding: 10px;"> <div> <table id="directory"> <thead> <tr> <th>Last Name</th> <th>First Name</th> <th>Email</th> <th>Campus Phone</th> <th>Room</th> <th>Department</th> <th>Title</th> </tr> </thead> <tbody> <tr> <td class="last"></td> <td class="first"></td> <td class="email"></td> <td class="campusphone"></td> <td class="room"></td> <td class="dept"></td> <td class="title"></td> </tr> </tbody> </table> </div> <br clear="all"> </div> <script type="text/javascript"> $(function(){ $('#directory').dataTable({ "bProcessing": true, "sAjaxSource": "source.php", "bAutoWidth": false }); }); </script>
When I run the page I get the error but it does show the correct number of records (but shows no records) so something is working.
Can someone tell me what I am doing wrong and how to make it work?
</script>
When I run the page I get the error but it does show the correct number of records (but shows no records) so something is working.
Can someone tell me what I am doing wrong?