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