首頁  >  文章  >  php教程  >  php 读取mysql后,json

php 读取mysql后,json

WBOY
WBOY原創
2016-06-06 19:42:29865瀏覽

代码如下: $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"}]

 

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

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn