Requested unknown parameter '0' from the data source for row 0" error...

Requested unknown parameter '0' from the data source for row 0" error...

rentawebguyrentawebguy Posts: 2Questions: 0Answers: 0
edited January 2013 in General
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:

[code]$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.
}[/code]


and here is the page that calls the list:

[code]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">



Campus Directory













#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;
}








Last Name
First Name
Email
Campus Phone
Room
Department
Title





















$(function(){
$('#directory').dataTable({
"bProcessing": true,
"sAjaxSource": "source.php",
"bAutoWidth": false
});
});

[/code]

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?





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?

Replies

  • rentawebguyrentawebguy Posts: 2Questions: 0Answers: 0
    I figured it out. My JSON data did not need the field names.

    So this:
    [code] 'sn' => $sn,
    'givenname' => $givenname,
    'samaccountname' => $samaccountname,
    'telephonenumber' => $telephonenumber,
    'physicaldeliveryofficename' => $physicaldeliveryofficename,
    'department' => $department,
    'title' => $title[/code]

    became this:
    [code] $sn,
    $givenname,
    $samaccountname,
    $telephonenumber,
    $physicaldeliveryofficename,
    $department,
    $title[/code]
  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    Good to hear you got it sorted.

    For anyone else with this issue, please see: http://datatables.net/faqs#unknown_parameter

    Allan
This discussion has been closed.