您好!欢迎来到云资源!本站资源24小时自动发货,海量精品课程资源免费下载!

php将从数据库中获得的数据转换成json格式并输出

header(content-type:application/json;charset=utf8);$results = array(); while ($row = mysql_fetch_assoc($result_query)) ...
header('content-type:application/json;charset=utf8');

$results = array();

  while ($row = mysql_fetch_assoc($result_query)) {
    $results[] = $row;
    }
  
  if($results){
      echo json_encode($results);
  
  }else{
      echo mysql_error();
  }


将查询到的数组存放到一个新的数组中,然后返回json格式(查询部分的语句已经省略)

开通vip
首页 导航 会员 客服 微信
QQ 微信 邮箱 TOP