I'm trying to made a table which can get database table value all row record. I've made it and I can do it but the data record just showing one data from the record database table, and it always looping the record value to the right while I clicked the button for showing the record into the table. Does anyone know what wrong with my code here?
This is the php, jquery and the html script, and the screenshot of the page:
$(document).ready(function() {
$("#ajaxButton").click(function() {
$.ajax({
type: "Post",
url: "employee.php",
success: function(data) {
var list = JSON.parse(data);
var tr = "";
$.each(list, function(i, v) {
tr = +"<tr>";
tr += "<td>" + v['no'] + "</td>";
tr += "<td>" + v['sensor1'] + "</td>";
tr += "<td>" + v['sensor2'] + "</td>";
tr += "<td>" + v['sensor3'] + "</td>";
tr += "<td>" + v['sensor4'] + "</td>";
tr += "<td>" + v['sensor5'] + "</td>";
tr += "<td>" + v['sensor6'] + "</td>";
tr += "<td>" + v['sensor7'] + "</td>";
tr += "<td>" + v['sensor8'] + "</td>";
tr += "<td>" + v['sensor9'] + "</td>";
tr += "<td>" + v['sensor10'] + "</td>";
tr += "<td>" + v['sensor11'] + "</td>";
tr += "<td>" + v['sensor12'] + "</td>";
tr += "<td>" + v['ambien'] + "</td>";
tr += "<td>" + v['average'] + "</td>";
tr += "<td>" + v['deffiasi'] + "</td>";
tr += "<td>" + v['status'] + "</td>";
tr += "</tr>";
});
$("#table_s tbody").append(tr);
}
});
});
});
row += '<td>' + data.rows[i].date + '</td>';
row += '<td>' + data.rows[i].company + '</td>';
row += '<td>' + data.rows[i].location + '</td>';
<html>
<head>
<script language="javascript" type="text/javascript" src="jquery-1.6.2.js"></script>
<script language="javascript" type="text/javascript" src="ajax.js"></script>
</head>
<body>
<form name="table_s" id="table_s" class="table_s">
<table id="table_s" class="table_s"cellspacing='0' class="js-serial" border="2">
<thead>
<tr>
<th><center>No.</center></th>
<th><center>S1</center></th>
<th><center>S2</center></th>
<th><center>S3</center></th>
<th><center>S4</center></th>
<th><center>S5</center></th>
<th><center>S6</center></th>
<th><center>S7</center></th>
<th><center>S8</center></th>
<th><center>S9</center></th>
<th><center>S10</center></th>
<th><center>S11</center></th>
<th><center>S12</center></th>
<th><center>Ambien</center></th>
<th><center>Average</center></th>
<th><center>Deff</center></th>
<th><center>Status</center></th>
</tr>
</thead>
<tbody>
<tr>
</tr>
</tbody>
</table>
<input type="button" value="Click Here" id="ajaxButton"/>
</body>
</html>
<?php
$con=mysqli_connect("localhost","root","","silo");
if (!$con) {
die('Could not connect: ' . mysql_error());
}
// Data for Titik1
$query = mysqli_query($con,"SELECT * FROM termocouple");
$rows = array();
while($tmp= mysqli_fetch_array($query)) {
$rows[] = $tmp;
}
echo json_encode($rows);
mysqli_close($con);
?>