How to show "No data available in table" or "No data available in table" If no data exist
How to show "No data available in table" or "No data available in table" If no data exist
Hi All!
Good day! I would like to seek for your assistance regarding my issue in datatable. Im trying to execute a datatable with no existing data but it shows this error:
DataTables warning (table id = 'DataTables_Table_0'): Requested unknown parameter '0' from the data source for row 0
how can i show "No data available in table" or "No data available in table" if the the datatable show empty table or data? and Which of the two .JS should i change? Please see the code below. Many Thanks!
front-end code(PHP-MYSQL):
<?php
include('config.php');
$sql = "SELECT * FROM opt_project_tracker where ID = 'XXX'";
$result = mysql_query($sql) or die('Query failed: ' . mysql_error());
while($rows=mysql_fetch_array($result)){
?>
<td align="left"><a href="form3.php?id=<?php echo $rows['ID']; ?>"><?php echo $rows['RRF_ID']; ?></a></td>
<td align="left"><?php echo $rows['Project_Name']; ?></td>
<td align="left"><?php echo $rows['Specialist_Assigned']; ?></td>
<td class="center">
<div class="controls center">
<a href="<?php echo $rows['ID']; ?>" title="Edit task" class="tip"><span class="icon12 icomoon-icon-pencil"></span></a>
<a href="<?php echo $rows['ID']; ?>" title="Remove task" class="tip"><span class="icon12 icomoon-icon-remove"></span></a>
</div>
</td>
</tr>
<?php
};
?>
</tbody>
Datatable.js:
/* Table initialisation */
$(document).ready(function() {
$('#example').dataTable( {
"sDom": "<'row'<'span6'l><'span6'f>r>t<'row'<'span6'i><'span6'p>>",
"sPaginationType": "bootstrap",
"oLanguage": {
"sLengthMenu": "_MENU_ records per page"
}
} );
} );
datatable.min.js:
$(document).ready(function() {
$('#example').dataTable({
"sDom": "<'row'<'span6'l><'span6'f>r>t<'row'<'span6'i><'span6'p>>",
"sPaginationType": "bootstrap",
"oLanguage": {
"sLengthMenu": "_MENU_ records per page"
}
})
});
Edited by Allan - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.
Answers
Can you do a View source in your browser when there are no rows in the HTML (i.e. when the error happens) and show me the generated HTML for the table please?
Thanks,
Allan
Hi Sir,
Good day! This is the generated table where the error encountered. Thank you.
You have an empty
tr
in thetbody
which is causing the issue. Remove that and the issue will be resolved.Allan
There is a PHP in it, if I remove that, it will not show the php mysql result. I am searching where I can customize the value of input text where I will replace it will some variables
It looks like your opening
tr
isn't inside thewhile
loop for reading and outputting the database read data.Allan