$sql = "SELECT * FROM `jos_users` LIMIT 0, 30 ";
$response = array();
$posts = array();
$result=mysql_query($sql);
while($row=mysql_fetch_array($result))
{
$id=$row['id'];
$id=$row['name'];
$posts[] = array('id'=> $title, 'name'=> $name);
}
$response['jos_users'] = $posts;
$fp = fopen('results.json', 'w');
fwrite($fp, json_encode($response));
fclose($fp);
我想将用户ID和名称提取到json文件。我认为id做错了code.can有人纠正了吗?
答案 0 :(得分:-2)
您正在覆盖$id
变量,然后您没有使用它......
$title
,$name
和$id
变量似乎有些混乱。
试试这个:
<?php
$sql = "SELECT * FROM `jos_users` LIMIT 0, 30 ";
$response = array();
$posts = array();
$result=mysql_query($sql);
while($row=mysql_fetch_array($result))
{
$id=$row['id']; //change here
$name=$row['name']; //change here
//change variables here
$posts[] = array('id'=> $id, 'name'=> $name);
}
$response['jos_users'] = $posts;
$fp = fopen('results.json', 'w');
fwrite($fp, json_encode($response));
fclose($fp);
?>