I am tearing out my hair...

I am tearing out my hair...

mrd05dmrd05d Posts: 45Questions: 6Answers: 3
edited August 2012 in General
Ok I have been coding a while but for some reason when it comes to the PHP sql statement to JSON etc I am loosing my mind... At this point i am unsure of my problem as i have fumbled my way through everything for hours. I set the ajax source and it seems to be working fine. The json data looks good to me from what i can tell. It took me 6 hours to get to where i am at now and i am now getting the following error:

"DataTables warning (table id = 'callQueue'): Requested unknown parameter '0' from the data source for row 0"

I tried adding mdata etc to no avail. I have attached the code below. Maybe someone else can guide me to the correct way to do things.

I have the following jquery
[code]

$('#callQueue').dataTable({

"sAjaxSource": "ajax/ajax_calls.php",
"aLengthMenu": [[10, 12, 15, 18, 20, 25, -1], [10, 12, 15, 18, 20, 25, "All"]],
"sPaginationType": "full_numbers",
"iDisplayLength": 20,
"bLengthChange": true,
"bProcessing": true,
"aoColumns": [
{ "mData": "Patient" },
{ "mData": "Accepting Doctor" },
{ "mData": "Referring Facility" },
{ "mData": "Diagnosis" },
{ "mData": "Call Status" },
{ "mData": "Actions" }
]
}),
[/code]


PHP FILE

[code]
<?php
$mysqli = new mysqli("localhost", "root", "", "vtc");

/* check connection */
if (mysqli_connect_errno()) {printf("Connect failed: %s\n", mysqli_connect_error()); exit();}

$query = "SELECT CONCAT_WS( ' ', patient.first, patient.last ) AS 'Patient', CONCAT_WS( ' ', doctor.first, doctor.last ) AS 'Accepting Doctor', facility.name AS 'Referring Facility', icd9codes.code_text AS 'Diagnosis', call_status.status AS 'Call Status', call_detail.call_id AS 'Actions'
FROM call_detail
LEFT JOIN patient ON call_detail.patient_id = patient.patient_id
LEFT JOIN doctor ON call_detail.doctor_id = doctor.doctor_id
LEFT JOIN facility ON call_detail.facility_id = facility.facility_id
LEFT JOIN icd9codes ON call_detail.primary_diag_id = icd9codes.icd9code_id
LEFT JOIN call_status ON call_detail.call_status_id = call_status.call_status_id";



$return_arr = array();
$result = $mysqli->query($query);

/* associative array */
while ($row = $result->fetch_array(MYSQLI_ASSOC)) {

$row_array = $row;
array_push($return_arr,$row_array);

}

$return_arr2['aaData'] = $return_arr;

echo json_encode($return_arr2);

/* free result set */
$result->free();

/* close connection */
$mysqli->close();

[/code]

The Returned Json: (shortened)

[code]
{"aaData":[{"Patient":"Guinevere Harper","Accepting Doctor":"Coby Nixon","Referring Facility":"A.G. Holley State Hospital","Diagnosis":"Lyme disease","Call Status":"Call Closed","Actions":"1"},{"Patient":"Guinevere Harper","Accepting Doctor":"Ignatius Boyle","Referring Facility":"All Childrens Hospital","Diagnosis":"Cholera due to vibrio cholerae el tor","Call Status":"Call Closed","Actions":"2"},{"Patient":"Guinevere Harper","Accepting Doctor":"Macy Brown","Referring Facility":"Arnold Palmer Hospital for Children","Diagnosis":"Cholera unspecified","Call Status":"Call Closed","Actions":"3"},{"Patient":"Guinevere Harper","Accepting Doctor":"Ishmael Sanford","Referring Facility":"Aventura Hospital Medical Center","Diagnosis":"Typhoid fever","Call Status":"Initial Information Collected ","Actions":"4"},{"Patient":"Guinevere Harper","Accepting Doctor":"Delilah Hickman","Referring Facility":"Baptist Childrens Hospital","Diagnosis":"Paratyphoid fever a","Call Status":"Initial Information Collected ","Actions":"5"},{"Patient":"Guinevere Harper","Accepting Doctor":"Brian Vincent","Referring Facility":"Baptist Hospital","Diagnosis":"Paratyphoid fever b","Call Status":"Initial Information Collected ","Actions":"6"},{"Patient":"Guinevere Harper","Accepting Doctor":"Aidan Nunez","Referring Facility":"Baptist Hospital of Miami","Diagnosis":"Paratyphoid fever c","Call Status":"Initial Information Collected ","Actions":"7"},{"Patient":"Guinevere Harper","Accepting Doctor":"Rylee Faulkner","Referring Facility":"Baptist Medical Center","Diagnosis":"Paratyphoid fever unspecified","Call Status":"Initial Information Collected ","Actions":"8"},{"Patient":"Guinevere Harper","Accepting Doctor":"Warren Valdez","Referring Facility":"Baptist Medical Center Beaches","Diagnosis":"Salmonella gastroenteritis","Call Status":"Initial Information Collected ","Actions":"9"}]}
[/code]

Replies

  • allanallan Posts: 63,535Questions: 1Answers: 10,475 Site admin
    At a guess, I would say you might have 7 columns defined in your HTML - but it is hard to say. Could you run your table through the debugger please: http://datatables.net/faqs#unknown_parameter

    Allan
  • mrd05dmrd05d Posts: 45Questions: 6Answers: 3
    I think you may be right there may be an issue with the table. I just have it set up as a bare bones table... My debug data is here:


    http://debug.datatables.net/oyedoy
  • mrd05dmrd05d Posts: 45Questions: 6Answers: 3
    The table looks like so:

    [code]



    Patient Name
    Accepting Doctor
    Referring Facility
    Diagnosis
    Call Status
    Actions





    [/code]
  • mrd05dmrd05d Posts: 45Questions: 6Answers: 3
    I was looking through the debugger and this looks odd to me (row information)...
    [code]
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    {
    "0": null,
    "1": null,
    "2": null,
    "3": null,
    "4": null,
    "5": null,
    "Patient": "Guinevere Harper",
    "Accepting Doctor": "Coby Nixon",
    "Referring Facility": "A.G. Holley State Hospital",
    "Diagnosis": "Lyme disease",
    "Call Status": "Call Closed",
    "Actions": "1"
    }
    [/code]
  • allanallan Posts: 63,535Questions: 1Answers: 10,475 Site admin
    > DataTables 1.9.1

    That's the problem :-)

    The mData option was introduced in DataTables 1.9.3. In 1.9.1 is it called mDataProp - does the same thing, but 1.9.3 renamed it (mDataProp will still work in 1.9.3 - it is fully backwards compatible!!). So your mData options are currently having no effect. Either rename to mDataProp or update to 1.9.3 and it spring to life :-)

    Allan
  • mrd05dmrd05d Posts: 45Questions: 6Answers: 3
    So I did as you said and updated to 1.9.3 and unfortunately its still not working. This time though it looks even further off like its now not passing the info back at all...

    http://debug.datatables.net/avoxin
  • mrd05dmrd05d Posts: 45Questions: 6Answers: 3
    Never mind i actually solved this... Thanks so much. for your help. And awesome job with the debugger.
This discussion has been closed.