我需要将php从数据库中提取的数据导出到json文件中,才能像这样输出到json文件中。我需要在每行之间换行。
"ID":"id.","Name":"name",
这是我的查询,它已经有id和name。但我不再知道如何将它们导出为文件。
while($row = mysql_fetch_array($result))
{
echo $row['id'];
echo $row['name'];
}发布于 2014-10-02 16:25:36
$data = [];
while($row = mysql_fetch_array()) {
$data[] = $row;
}
$txt = json_encode($data);
$myfile = fopen("newfile.txt", "w") or die("Unable to open file!");
fwrite($myfile, $txt);
fclose($myfile);答案将是这样的:
[
{ "id": "idvalue", "name": "namevalue" },
...
]https://stackoverflow.com/questions/26156885
复制相似问题