Javascript可以';我无法读取我的json数组
因此,我从数据库中获取了一些数据,并使用以下代码将其放入json数组中: getDataFromDB:Javascript可以';我无法读取我的json数组,javascript,php,jquery,mysql,json,Javascript,Php,Jquery,Mysql,Json,因此,我从数据库中获取了一些数据,并使用以下代码将其放入json数组中: getDataFromDB: <?php include"connectToDB.php"; //voert de volgende query uit $result = $db->query("SELECT * FROM youtubevideos"); $array = array(); while($row = $result->fetch_assoc()) { $array = $
<?php
include"connectToDB.php";
//voert de volgende query uit
$result = $db->query("SELECT * FROM youtubevideos");
$array = array();
while($row = $result->fetch_assoc()) {
$array = $row;
echo json_encode($array);
}
?>
在console.log(字段)中,它应该给我数组中的所有数据。但由于某种原因,我的控制台是空的。它似乎无法读取我的数组。但有趣的是。。。
当我键入exit()时代码>在这行代码之后echo json_encode($array)
在我的php文件中,它可以以某种方式读取它。但问题是它只给我数据库中的一行。当然,我想从数据库中获取所有数据,所以我不能使用exit()代码>。他们对我做错了什么还有其他建议吗?
谢谢 php文件返回多个json
字符串,因为echo
在for
循环中
将您的代码更改为此
<?php
include"connectToDB.php";
//voert de volgende query uit
$result = $db->query("SELECT * FROM youtubevideos");
$array = array(); // you can remove this
while($row = $result->fetch_assoc()) {
$array[] = $row;
}
echo json_encode($array);
您的php文件返回多个json
字符串,因为您echo
在for
循环中
将您的代码更改为此
<?php
include"connectToDB.php";
//voert de volgende query uit
$result = $db->query("SELECT * FROM youtubevideos");
$array = array(); // you can remove this
while($row = $result->fetch_assoc()) {
$array[] = $row;
}
echo json_encode($array);
您的php文件返回多个json
字符串,因为您echo
在for
循环中
将您的代码更改为此
<?php
include"connectToDB.php";
//voert de volgende query uit
$result = $db->query("SELECT * FROM youtubevideos");
$array = array(); // you can remove this
while($row = $result->fetch_assoc()) {
$array[] = $row;
}
echo json_encode($array);
您的php文件返回多个json
字符串,因为您echo
在for
循环中
将您的代码更改为此
<?php
include"connectToDB.php";
//voert de volgende query uit
$result = $db->query("SELECT * FROM youtubevideos");
$array = array(); // you can remove this
while($row = $result->fetch_assoc()) {
$array[] = $row;
}
echo json_encode($array);
这部分代码在数据库返回的每一行上输出一个JSON数组:
while($row = $result->fetch_assoc()) {
$array = $row;
echo json_encode($array);
}
您应该首先向和数组添加项,然后在循环外部输出json编码的数组
while($row = $result->fetch_assoc()) {
$array[] = $row;
}
echo json_encode($array);
试试看。这部分代码将在数据库返回的每一行上输出一个JSON数组:
while($row = $result->fetch_assoc()) {
$array = $row;
echo json_encode($array);
}
您应该首先向和数组添加项,然后在循环外部输出json编码的数组
while($row = $result->fetch_assoc()) {
$array[] = $row;
}
echo json_encode($array);
试试看。这部分代码将在数据库返回的每一行上输出一个JSON数组:
while($row = $result->fetch_assoc()) {
$array = $row;
echo json_encode($array);
}
您应该首先向和数组添加项,然后在循环外部输出json编码的数组
while($row = $result->fetch_assoc()) {
$array[] = $row;
}
echo json_encode($array);
试试看。这部分代码将在数据库返回的每一行上输出一个JSON数组:
while($row = $result->fetch_assoc()) {
$array = $row;
echo json_encode($array);
}
您应该首先向和数组添加项,然后在循环外部输出json编码的数组
while($row = $result->fetch_assoc()) {
$array[] = $row;
}
echo json_encode($array);
试试看。在php部分,为什么不向数组中添加元素,现在将数组设置为行,更改为$array[]=$row
将行推入数组,然后将回音移动到php部分的while循环之后,为什么不向数组中添加元素,现在将数组设置为行,更改为$array[]=$row
将一行推入数组,然后将回音移动到php部分的while循环之后为什么不向数组添加元素,现在将数组设置为row,更改为$array[]=$row
将一行推入数组,然后将回音移动到while循环之后在php部分中,为什么不向数组添加元素,现在将数组设置为row,更改为$array[]=$row
将一行推入数组,然后将回音移动到while循环之后您不需要这一行:$array=array()
@CodeGodie你是对的,我添加了它作为一个注释来匹配你的注释:)你不需要这行:$array=array()
@CodeGodie你是对的,我添加了它作为一个注释来匹配你的注释:)你不需要这行:$array=array()
@CodeGodie你是对的,我添加了它作为一个注释来匹配你的注释:)你不需要这行:$array=array()
@CodeGodie您是对的,我将其添加为注释以匹配您的注释:)