Home >Backend Development >PHP Tutorial >php将数据库查询结果转换为json格式解决思路

php将数据库查询结果转换为json格式解决思路

WBOY
WBOYOriginal
2016-06-13 12:09:21939browse

php将数据库查询结果转换为json格式
数据库查询结果如下:
要把它转化为如下格式的json,第一个属性是日期对应的unix时间戳,第二个是sales

 

<br /><?php<br />include_once 'DB_connmssql.php';<br />header("Content-Type:text/html;charset=utf-8");<br /><br />		$sql_initbest="<br />		select outdate,SUM(nb*endprice) sales from BI_sale<br />where endprice<>0<br />group by outdate";<br />		$query = mssql_query($sql_initbest);<br />		<br />		while($row=mssql_fetch_array($query)){<br />			<br />		array_push($result["data"] , $row);<br />		}<br />			<br />		<br />		echo json_encode($result);<br />		<br />?><br />

不知道该怎么转日期格式,拼接的json格式也不对求大神指教下
------解决思路----------------------
while($row=mssql_fetch_array($query)){<br />    $result["data"][] = array(  strtotime($row["outdate"]).'000', $row["sales"] );<br />}<br />echo json_encode($result);

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