내 문제를 해결하려면 도움이 필요합니다. 데이터베이스에서 테이블 tbody로 데이터를 선택하는 동안 문제가 있습니다. 나는 그것을 만들려고 노력했지만 그것을 실행하려고 시도했지만 데이터를 표시 할 수는 없다. HTML, PHP 및 Javascript 파일을 다른 파일 형식으로 분리했습니다. 도와주세요 ..! 예를 들어 주시면 감사하겠습니다.
THIS
내 CODE된다PHP 코드
<?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['no'];
$rows[] = $tmp['s_tanggal'];
$rows[] = $tmp['silo'];
$rows[] = $tmp['sensor1'];
$rows[] = $tmp['sensor2'];
$rows[] = $tmp['sensor3'];
$rows[] = $tmp['sensor4'];
$rows[] = $tmp['sensor5'];
$rows[] = $tmp['sensor6'];
$rows[] = $tmp['sensor7'];
$rows[] = $tmp['sensor8'];
$rows[] = $tmp['sensor9'];
}
$result = array();
array_push($result,$rows);
print json_encode($result, JSON_NUMERIC_CHECK);
mysqli_close($con);
?>
HTML 코드
<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>
<td id="td_s0"></td>
<td id="td_s1"></td>
<td id="td_s2"></td>
<td id="td_s3"></td>
<td id="td_s4"></td>
<td id="td_s5"></td>
<td id="td_s6"></td>
<td id="td_s7"></td>
<td id="td_s8"></td>
<td id="td_s9"></td>
<td id="td_s10"></td>
<td id="td_s11"></td>
<td id="td_s12"></td>
<td id="td_s13"></td>
<td id="td_s14"></td>
<td id="td_s15"></td>
<td id="td_s16"></td>
</tr>
</tbody>
</table>
JS 코드
,$(document).on('click','#ok',function(e) {
$.ajax({
url: '../php/termo_sel.php',
data: {datepicker: 'val1', silo : 'val2'}, //Pass data to PHP by POST
type: 'post',
dataType: 'json',
success: function(data) //Whatever is put in echo in PHP is returned here
{
$('#table_s').append(data);
}
});
clearInput();
});
function clearInput() {
$("#form_input :input").each(function() {
$('#s1').val('');
$('#s2').val('');
$('#s3').val('');
$('#s4').val('');
$('#s5').val('');
$('#s6').val('');
$('#s7').val('');
$('#s8').val('');
$('#s9').val('');
$('#s10').val('');
$('#s11').val('');
$('#s12').val('');
$('#amb').val('35.0');
$('#avr').val('');
$('#deff').val('');
$('#sts').val('');
});
}
당신은 얻고있는 출력의 스크린 샷을 추가 할 수 있습니까 –
스크린 샷으로 코드를 편집했습니다 그 그림에서 만든 Thead 하단에 데이터베이스 값을 바로 표시해야합니다 –
Pls 브라우저의 개발자 콘솔이 $ ('# table_s')을 업데이트합니다. append (data); JS 코드에 추가하고 console.log (데이터)를 추가하십시오. 그런 다음 여기에있는 내용을 다시 말하고 덧글로 붙여 넣으십시오. –