热搜:NVER node 开发 php

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

2024-09-16 13:45:01
大家看看我的语法哪里有问题,输不出来数据。

$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 编码的数据