PHP 将 mysql-results double 添加到数组中。
$query = "select * from tblRecords where record_category = '" . $cat . "' order by record_artist";
$result = $link->query($query);
这是我用来获取结果的查询,效果很好。
while($record = $result->fetch_array()) {
array_push($arr_result, $record);
}
这是我将每个值添加到数组中的代码。但在
echo json_encode($arr_result);
这是我收到的结果集之后:
https://i.sstatic.net/Gmggl.png
我做错了什么?
$query = "select * from tblRecords where record_category = '" . $cat . "' order by record_artist";
$result = $link->query($query);
This is the query that I use, to fetch the results, this works ok.
while($record = $result->fetch_array()) {
array_push($arr_result, $record);
}
And this is the code I add each value to the array. But after
echo json_encode($arr_result);
This is the result set I receive:
https://i.sstatic.net/Gmggl.png
What am I doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你需要通过=>
MYSQL_ASSOC
值到fetch_array
函数查看:http://php.net/manual/en/function.mysql-fetch-array.php
you need to pass = >
MYSQL_ASSOC
value tofetch_array
functionlook on : http://php.net/manual/en/function.mysql-fetch-array.php
PHP中没有像
fetch_array()
这样的函数,我认为你使用的是预定义的MySQL类,它内部调用mysql_fetch_array()
,所以检查这个类,实际上你是获得正确的结果,但通过使用MYSQL_BOTH
(默认),您将获得一个同时具有关联索引和数字索引的数组。使用
Or
您一定忘记了使用
fetch_array()
编写参数。参考
There is no function like
fetch_array()
in PHP, I think you're using a predefined MySQL class which internally callsmysql_fetch_array()
, so check the class, actually you are getting correct result but by usingMYSQL_BOTH
(default), you'll get an array with both associative and number indices.Use
Or
You must have forgotten to write a argument with
fetch_array()
.reference
fetch_array
返回数字数组和关联数组 - 相反,请使用fetch_array_assoc()
fetch_array
is returning both a numeric and an associative array - instead, usefetch_array_assoc()