我想显示来自MySQL DB的数据。表格let appDelegate = UIApplication.shared.delegate as! AppDelegate
let managedContext = appDelegate.persistentContainer.viewContext
let entity = NSEntityDescription.entity(forEntityName: "PillTook", in:managedContext)
for var index in 0...27 {
let value = NSManagedObject(entity: entity!, insertInto: managedContext)
value.setValue(false, forKey: "took")
pillTook.append(value)
}
do {
try managedContext.save()
} catch let error as NSError {
print("Could not save \(error), \(error.userInfo)")
}
'有4列:fname,lname,学校和城市。该表中有10行数据。所以我的代码是:
mytable1
在myapp.js中我有:
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 ;
我无法显示任何数据。我希望能够显示表中包含10行数据的所有数据。我究竟做错了什么?
感谢。
答案 0 :(得分:1)
如果您使用上面相同的代码发送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 );
}
});