问一个mysql遍历转json的有关问题

WBOY
Release: 2016-06-13 13:11:09
Original
1262 people have browsed it

问一个mysql遍历转json的问题.
我用PHP给Jquery AJAX传值.用$.parseJSON解析
如果要查一条记录,我已经学会了.如果要穿传多条记录.就有问题了.


//一条记录
//$row = mysql_fetch_array( $result );
//echo json_encode ($row);
//多条记录
while ($row = mysql_fetch_array($result)) {
echo json_encode($row);
};


按这个方法,如果有两条数据.回传这样一个json

{"0":"68","id":"68","1":"90","top":"90","2":"120","lef":"120","3":"u2","uid":"u2"}{"0":"92","id":"92","1":"40","top":"40","2":"320","lef":"320","3":"u1","uid":"u1"}

用$.parseJSON就无法解析了.请问有一个办法吗?

------解决方案--------------------
while ($row = mysql_fetch_array($result)) {
$res[] = $row;
}
echo json_encode($res);

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template