[英]how to format mysql results to json php
mysql table mysql表
ID >> Name >> Salary
$row_set << database table information. $ row_set <<数据库表信息。
my problem is when i use 我的问题是当我使用
json_encode($row_set);
the output will be something like this: 输出将是这样的:
[{"0":"1","ID":"1","1":"x","Name":"x","2":"12345","Salary":"12345"}]
i want the results to be something like this 我希望结果是这样的
[{"ID":"1","Name":"x","Salary":"12345"}]
how to do that ? 怎么做 ?
EDIT :: FULL CODE 编辑::完整代码
$result = mysql_query("SELECT * FROM emp");
while($row = mysql_fetch_array($result))
{
$row_set[] = $row;
}
echo json_encode($row_set);
I presume you are using mysql_fetch_array
to get the row at the moment. 我想您现在正在使用
mysql_fetch_array
来获取行。
Try mysql_fetch_array($resource, MYSQL_ASSOC)
(note the 2nd parameter!) 尝试
mysql_fetch_array($resource, MYSQL_ASSOC)
(注意第二个参数!)
or mysql_fetch_assoc()
. 或
mysql_fetch_assoc()
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.