开发者

how to format mysql results to json php

mysql table

ID >> Name >> Salary

$row_set <开发者_运维知识库;< database table information.

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.

Try mysql_fetch_array($resource, MYSQL_ASSOC) (note the 2nd parameter!)

or mysql_fetch_assoc().

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜