我想显示来自 MySQL DB 的数据。表“mytable1
”有 4 列:fname、lname、school 和 city。该表中有 10 行数据。所以我的代码是:
DB CONNECTION
$sql = "SELECT * FROM mytable1";
$result = $conn->query($sql);
$mycontent = array();
while($row = $result->fetch_assoc()){
array_push($mycontent, $row);
}
$newcontent = json_encode($mycontent);
echo $newcontent ;
在 myapp.js 中我有:
$$.ajax({
url:"ajaxdbtest.php",
type:"get",
dataType:"json",
success: function(data)
{
$$( ".showcontenthere" )
.append( "<br />data.fname )
.append( "<br />data.lname )
.append( "<br />data.school )
.append( "<br />data.city );
}
});
我无法显示任何数据。我希望能够显示包含 10 行数据的表中的所有数据。我究竟做错了什么?
谢谢。
最佳答案
如果您使用上面相同的代码来发送 ajax 调用,那么您需要像这样修复它:
$$.ajax({
url:"ajaxdbtest.php",
type:"get",
dataType:"json",
success: function(data)
{
$$( ".showcontenthere" )
.append( "<br />" + data.fname )
.append( "<br />" + data.lname )
.append( "<br />" + data.school )
.append( "<br />" + data.city );
}
});
关于php - 在framework7应用程序中显示数据库数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41208363/