Home  >  Article  >  php教程  >  php 读取mysql后,json

php 读取mysql后,json

WBOY
WBOYOriginal
2016-06-06 19:42:29865browse

代码如下: $result=mysql_query("select g.*,u.ID as companyID,u.company,u.address,u.phone from tblgood g join tbluser u on g.companyID=u.ID where g.code=$code"); while($row=mysql_fetch_array($result)) { $image=iconv("GBk", "UTF-8//IGNORE",

代码如下:

$result=mysql_query("select g.*,u.ID as companyID,u.company,u.address,u.phone from tblgood g join tbluser u on g.companyID=u.ID where g.code=$code");
while($row=mysql_fetch_array($result))
{
     $image=iconv("GBk", "UTF-8//IGNORE", $row['image']);
  $tmp=array('goodID'=>$row['ID'],'goodName'=>$row['name'],'goodPrice'=>$row['price'],'memo'=>$row['memo'],'image'=>$image,'companyID'=>$row['companyID'],'companyName'=>$row['company'],'companyAdd'=>$row['address'],'companyPhone'=>$row['phone']);
  array_push($arr,$tmp);
}
mysql_close($con);
return json_encode($arr);

其中$row['image']数据库中存放的是图片地址,例如http://www.baidu.com/a.jpg

返回的json 为:/反斜线全部变成了\/

[{"goodID":"1","goodName":"巧乐兹","goodPrice":"2","memo":"haochi ","image":"images\/panda.jpg","companyID":"1","companyName":"柚子小店","companyAdd":"深圳","companyPhone":"05341255"}]

 

这是怎么回事呢???有那位知道??

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:PHP调用C++DLL的问题Next article:ajax与PHP 传参问题