I have a php script that encodes my db table into an array. I echo the json_encode and it echos just fine. script :
<?php
$host="localhost"; // Host name
$username="root"; // Mysql username
$password="testdbpass"; // Mysql password
$db_name="test"; // Database name
// Connect to server via PHP Data Object
$dbh = new PDO("mysql:host=localhost;dbname=test", $username, $password);
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$array = $dbh->query("SELECT id, anum, first, last,
why, comments, aidyear, additional_req,
signintime FROM inoffice WHERE
counselorname IS NULL")->fetchAll(PDO::FETCH_ASSOC);
echo json_encode($array);
?>
and the output of this :
JSON array :
[{"id":"7","anum":"B00000000","first":"rixhers","last":"ajazi","why":"Other","comments":"Jut need some help!!!","additional_req":"","aidyear":"12-13","signintime":"2013-01-16 09:08:35"},{"id":"8","anum":"A00000000","first":"rixhers","last":"ajazi","why":"Appeal","comments":"","additional_req":"","aidyear":"12-13","signintime":"2013-01-16 09:28:57"},{"id":"9","anum":"A00000000","first":"rixhers","last":"ajazi","why":"Appeal","comments":"","additional_req":"","aidyear":"12-13","signintime":"2013-01-16 10:12:07"},{"id":"10","anum":"A00000000","first":"rixhers","last":"ajazi","why":"Appeal","comments":"","additional_req":"","aidyear":"12-13","signintime":"2013-01-16 11:19:18"}]
I then have a page that end user can visit that should extract the data and then place it into a table. For some reason I can not get it TO post to my first table on that page. The table must include rows for however mysql table results there are.
these are my jquery scripts I have running on the page :
<head>
<script src="core/media/js/jquery.js" type="text/javascript"></script>
<script src="core/media/js/jquery.dataTables.js" type="text/javascript"></script>
<script type="text/javascript" src="core/media/js/install.js"></script>
<script type="text/javascript">
$.ajax({
url: 'core/media/js/getdatainoffice.php',
type: 'GET',
async: false,
dataType: 'json',
success: function (result) {
var insert = '';
$.each(result, function() {
insert += '<tr><td>' + id + '</td><td>' + anum + '</td><td>' + first + '</td><td>' + last + '</td><td>' + why +
'</td><td>' + comments + '</td><td>' + additional_req + '</td><td>' + aidyear + '</td><td>'
+ signintime + '</td></tr>';
});
$('#datatables tr').after(insert);
}
});
</script>
this is my table :
table id='datatables' class='display'>
<thead>
<tr>
<th>Session ID </th>
<th>A Number</th>
<th>First Name</th>
<th>Last Name</th>
<th>Reason for visit</th>
<th>Comments</th>
<th>Aid Year</th>
<th>Additional Requirements</th>
<th>Signin Time</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
Any help would or explanations would be lovely. I have been reading off this site but to no avail.
More information : I am using a jquery plugin called datatables and I need to populate that table.
The ultimate goal for this project is to have the tables dynamically update when ever there is a new row inserted or a row be updated. Any help would be great!