日期:2014-05-16  浏览次数:20334 次

数据记录转为标准的json字符串
/*
将查询结果集转为JSON字符串
*/
function DBToJSONString($jsonItem,$sqlstr){
  $data=mssqlquery($sqlstr);
  $rows=mssql_num_rows($data);
  $fnNums=mssql_num_fields($data);
  $SubjectList='';
  $SubjArray='';
  while ($row=mssql_fetch_array($data)) {
     for ($i=0;$i<$fnNums;++$i){
		 $SubjectList.="\"".mssql_field_name($data,$i)."\":\"".$row[$i]."\",";
	} 
    $SubjectList=substr($SubjectList,0,-1);
	$SubjArray.="{".$SubjectList."},";	
	$SubjectList='';
  }
  mssql_free_result($data);
  $SubjArray="\"".$jsonItem."\":[".substr($SubjArray,0,-1)."]";
  return $SubjArray;
}