我有这样的代码编码一个完美的JSON
$md_query = "SELECT * FROM table ORDER BY id ASC";
$md_result = mysql_query($md_query, $con);
header('Cache-Control: no-cache, must-revalidate');
header('Content-type: application/json');
while($md_row=mysql_fetch_array($md_result))
$data_row = array(
'id' => $md_row['id'],
'type' => $md_row['type'],
'title' => $md_row['title'],
'content' => $md_row['content'],
'author' => $md_row['postedby'],
'post_date' => $md_row['posteddate'],
'publish' => $md_row['publish']
);
print json_encode($data_row); `
,但我只显示1个记录......没有人如何解决这个问题?
该mysql扩展已过时,并在其弃用的方式。新代码应该使用mysqli或PDO,它们都具有重要的优点,例如支持预处理语句。不要使用['SELECT *'](http://stackoverflow.com/questions/321299);只选择你需要的列。 – outis
您将在每次迭代中重置$ data_row。所有你需要做的就是将所有的行存储到一个数组中,并且'json_encode($ final_array)' – Broncha