Home > Backend Development > PHP Tutorial > 大家看看我的语法哪里有问题,输不出来数据。

大家看看我的语法哪里有问题,输不出来数据。

WBOY
Release: 2016-06-23 14:14:03
Original
790 people have browsed it

$data = array();
$db = pc_base::load_model('content_model');
$sql="select a.id,a.title,a.url,a.status,a.catid,a.thumb,b.id,b.content from v9_news a,v9_news_data b where a.id=b.id and a.catid=7";
$k=$db->query($sql);
while($r = mysql_fetch_array($k)){
$data[]= (object)array('image'=>$r[thumb],  'title'=>$r[title]);
}

// 随机抽取9条记录以模拟实际情况
$keys = array_rand($data, 10);

$json = array();
foreach($keys as $key)
{
$json[] = $data[$key];
}

echo json_encode( $json );


回复讨论(解决方案)

print_r($data);
看看有些什么

json_encode 只能处理 utf-8 编码的数据

source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template