"No Data Available In Table" from Dynamically Generated Table (PHP/MySQL)

"No Data Available In Table" from Dynamically Generated Table (PHP/MySQL)

macmanuimacmanui Posts: 5Questions: 0Answers: 0
edited March 2011 in General
I've got things up and running and the script is working (search appears, along with other UI elements) but nothing actually works.

My table displays (as it did before) but the last row of the table says "No Data Available In Table" and then displays "Showing 0 of 0 entries". But it's displaying this info right under the table!

My table is generated dynamically from a mysql_query response in PHP:

[code]
function displayDBResult($result,$tableName)
{
$numOfFields = mysql_num_fields($result);
$content = '
' . ucfirst($tableName) . ' Table' . PHP_EOL;
$content .= '
' . PHP_EOL;

$content.='' . PHP_EOL;
$content.= '';
for ($i=0; $i<$numOfFields; $i++)
{
$heading = mysql_fetch_field($result,$i);
$content.= '' . $heading->name . '' . PHP_EOL;
}


$content.= '' . PHP_EOL;
$content.='' . PHP_EOL;
$content.='' . PHP_EOL;

while($row = mysql_fetch_row($result))
{
$content.= '';
foreach($row as $field)
//Populate each row of the table field by field and substitute a dash for blank fields
if (strlen($field) > 0) {
$content.= '' . $field . '' . PHP_EOL;
}
else {
$content.=' - ' . PHP_EOL;
}
$content.= '' . PHP_EOL;
$content.='' . PHP_EOL;
}
$content.= '

' . PHP_EOL;
return $content;
}
[/code]

Like I said, the table displays fine - it's right there on the page, but I don't think DataTables is seeing it and I'm not sure why. Looking at the HTML source for the page (after it's rendered) shows a table that fits the formatting rules for DataTables exactly. So any help would be most...helpful.

Thanks!

Replies

  • macmanuimacmanui Posts: 5Questions: 0Answers: 0
    Oh - I forgot to mention that server-side processing is a no-go. I can't be resubmitting queries every time a new sort is instituted.
  • compcentralcompcentral Posts: 40Questions: 0Answers: 0
    What does the javascript in the head of your html document look like?
  • macmanuimacmanui Posts: 5Questions: 0Answers: 0
    It looks like this:

    [code]


    [/code]
  • compcentralcompcentral Posts: 40Questions: 0Answers: 0
    edited March 2011
    I assume that you have something like this after those lines -- make sure the id of your table (min-table) matches:
    [code]

    $(document).ready(function(){
    $('#min-table').dataTable();
    });

    [/code]
  • macmanuimacmanui Posts: 5Questions: 0Answers: 0
    I do have that script in the file. Changing all the to just made everything in the table look like a column heading. And there is still the interface box from the script

    Above the table:
    Show (drop down - 10) entries
    Search (text area)

    The last line *in* the table says: No data available in table.

    Below Table:
    Showing 0 of 0 entries.
  • compcentralcompcentral Posts: 40Questions: 0Answers: 0
    yes... i retracted the / suggestion, but I guess you saw it before I editted my post. is correct for the body of the table.

    can you post a link to the table in question so we can better assist you?
  • macmanuimacmanui Posts: 5Questions: 0Answers: 0
    I'll try to post a link as soon as I can. The server it's on can only be accessed via our own network or a vpn. I had to put in a request for a "public" site - as soon as it's approved I'll move the relevant files over and toss you a link.

    Thanks for the help!
  • compcentralcompcentral Posts: 40Questions: 0Answers: 0
    sure thing. I'm pretty new to datatables too and I had a bit of difficulty getting response here on the forum, so if I can offer any help, I will.
  • dbousquetdbousquet Posts: 1Questions: 0Answers: 0
    Hello,
    I faced the same symptoms, the cause was that a tag was present before tag.
  • dbettdbett Posts: 1Questions: 0Answers: 0
    Thank you, dbousquet ... I was fritzing around with this problem for hours and your suggestion that it was the tag before the solved it!

    Merci! Merci!
  • RaginiRagini Posts: 1Questions: 0Answers: 0
    edited April 2012
    Hi, I have table in form in which row is added dynamically, 1st row is fine its data also storing in db, have problem from 2nd data from 2nd row not storing in db and even it is not performing like row 1, pls can one find solution for this.....
  • mssaidymssaidy Posts: 1Questions: 0Answers: 0
    mssaidy June 11 2012
    I populate the table from an XML file. The data is displayed in the table. But the UI features have not effect on the table. At the same time, I get the message "No data available in the table". The JS code:

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



    JQuery Easy XML Read Example

    @import "../../media/css/demo_page.css";
    @import "../../media/css/demo_table.css";




    $(document).ready(function() {
    $('#example').dataTable();
    } );


    function BuildStudentHTML(studentName,studentAge,studentPhone,studentSSN){
    var rc = document.createElement('tr');
    rc.setAttribute("class","odd gradeX");
    var cell1 = document.createElement('td');
    var cell1Text = document.createTextNode(studentName);
    cell1.appendChild(cell1Text);
    rc.appendChild(cell1);

    var cell2 = document.createElement('td');
    var cell2Text = document.createTextNode(studentAge);
    cell2.appendChild(cell2Text);
    rc.appendChild(cell2);

    var cell3 = document.createElement('td');
    var cell3Text = document.createTextNode(studentPhone);
    cell3.appendChild(cell3Text);
    rc.appendChild(cell3);

    var cell4 = document.createElement('td');
    var cell4Text = document.createTextNode(studentSSN);
    cell4.appendChild(cell4Text);
    rc.appendChild(cell4);

    return rc;
    }




    DataTables - flexible width example




    name
    age
    phone
    ssn




    var tblBody = document.createElement("tbody");

    $.get("students.xml",{},function(xml){
    // Run the function for each student tag in the XML file

    $('student',xml).each(function(i) {
    studentName = $(this).find("name").text();
    studentAge = $(this).find("age").text();
    studentPhone = $(this).find("phone").text();
    studentSSN = $(this).find("ssn").text();

    // Build row HTML data and store in string
    var current_row = BuildStudentHTML(studentName,studentAge,studentPhone,studentSSN);
    tblBody.appendChild(current_row);
    });
    $('#example').append(tblBody);
    });






    Please, can you inform me where is the problem.
    Thank you in advance
This discussion has been closed.