Table is blank, what am I doing wrong?
Table is blank, what am I doing wrong?
dodgebros
Posts: 1Questions: 1Answers: 0
I am new to datatables and I am having trouble getting a simple webpage with a grid to work.
Below is the webpage code:
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- <link rel="stylesheet" type="text/css" href="//cdn.datatables.net/1.10.7/css/jquery.dataTables.css"> -->
<link rel="stylesheet" type="text/css" href="//cdn.datatables.net/plug-ins/1.10.7/integration/jqueryui/dataTables.jqueryui.css">
<link rel="stylesheet" type="text/css" href="//cdn.datatables.net/plug-ins/1.10.7/integration/jqueryui/dataTables.jqueryui.js">
<script type="text/javascript" charset="utf-8" src="./jquery.js"></script>
<script type="text/javascript" charset="utf-8" src="./jquery.dataTables.js"></script>
</head>
<body>
<script type="text/javascript">
$(document).ready(function() {
$('#example').dataTable( {
"processing": true,
"serverSide": true,
"ajax": "incidents.php"
} );
} );
</script>
<table id="example" class="display" cellspacing="0" width="100%">
<thead>
<tr>
<th>ID</th>
<th>Incident Number</th>
<th>Incident Date</th>
<th>incident time</th>
<th>Location Type</th>
<th>Random Number</th>
</tr>
</thead>
<tbody>
<tr></tr>
</tbody>
</table>
</body>
</html>
This is the code in incidents.php:
<?php
$db = mysql_connect("127.0.0.1", "root", "")
or die("Could not connect to server");
mysql_select_db('ajax', $db);
$sql = "SELECT pid AS id, incident_number, incident_date, incident_time, location_type, random_number FROM incidents";
$data = mysql_query($sql, $db);
if($data == true)
{
// echo 'query worked';
// echo '</bf>';
$d = mysql_fetch_assoc($data);
}
else
{
die("Querying Failed");
exit();
}
echo json_encode($d);
<?php
>
```
?>
This is the output of incidents.php if you just run incident.php:
{"id":"1","incident_number":"1005","incident_date":"0000-00-00","incident_time":"08:20:00","location_type":"here","random_number":"123"}```
I realize that I need to right code to load all of the rows of data in $data to $d but for now this should work ... I must be missing something.
Thanks,
TD
This discussion has been closed.