2012-03-28 54 views
0

我想要一个MySQL资源ID转换成JSON对象发送作为Ajax调用 响应这是一个从来就试图用我怎么可以转换的MySQL结果为JSON对象使用PHP

代码
<?php 
require_once 'config.php'; 
$sql="SELECT * FROM `inquiry` WHERE 1"; 
$res=mysql_query($sql); 
if($res) 
echo json_encode($res); 
?> 

,我得到这个错误信息

Warning: [json] (php_json_encode) type is unsupported, encoded as null in /home/smartco/public_html/kb/q.php on line 6 

我怎么能做到这一点

回答

2

将代码更改为

$res = mysql_query($sql); 
while($data = mysql_fetch_array($res)) { 
$output[] = $data; 
} 
echo json_encode($output); 

您正在编码资源ID。

相关问题