"No Data Available In Table" from Dynamically Generated Table (PHP/MySQL)
"No Data Available In Table" from Dynamically Generated Table (PHP/MySQL)
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!
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!
This discussion has been closed.
Replies
[code]
[/code]
[code]
$(document).ready(function(){
$('#min-table').dataTable();
});
[/code]
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.
can you post a link to the table in question so we can better assist you?
Thanks for the help!
I faced the same symptoms, the cause was that a tag was present before tag.
Merci! Merci!
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