【发布时间】:2017-08-17 00:30:50
【问题描述】:
我需要帮助来显示从数据库中选择数据值到 html 表中的特定位置。 我已经编写了显示它的代码,但它会在 html 表的索引 0 中显示数据。
有人知道如何使数据显示在 html 表的索引 1 处吗? 我尝试更改索引,但无法显示它。 这是我的代码:
$(document).ready(function(){
$.ajax({
type: "Post",
url: "../php/bkk/bkk_isel.php",
success: function(data){
var list = JSON.parse(data);
for(var i = 0; i < list.length; i++){
$('#mat').val((list[i]['material']));
$('#lok').val((list[i]['lokasi']));
$('#kpl').val((list[i]['kapal']));
$('#po_numb').val((list[i]['po']));
var tr = "<tr>";
tr += "<td>"+list[i]['tanggal']+"</td>";
tr += "<td>"+list[i]['no_pol']+"</td>";
tr += "<td>"+list[i]['netto']+"</td>";
tr += "</tr>";
$("#table_s tbody").append(tr);
}
return false;
}
});
});
这是我使用的 {data}。我对数据使用 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 temp2");
$rows = array();
while($tmp= mysqli_fetch_array($query)) {
$rows[] = $tmp;
}
echo json_encode($rows);
mysqli_close($con);
?>
【问题讨论】:
-
在变量“数据”中接收到什么值。你也可以发布一个样本吗
-
我已经编辑了我的代码。我给出了检索 {data} 的代码
标签: php html ajax select html-table