我想遍历 MySQL 结果,这是一个 Freebase MID 数组,我希望输出是 Freebase 文章的名称!
这是我的代码:
$query = "SELECT `mid` FROM `items`";
$result = mysql_query($query);
$count = 1;
while ($row = mysql_fetch_array($result)) {
$mid = $row['mid'];
$simple_query = array('name'=> null, 'mid'=>$mid);
$q_array = array('q'.$count=>array('query'=>$simple_query));
array_push ($query_array, $q_array );
$count++;
}
$jsonquerystr = json_encode($query_array);
$apiendpoint = "http://api.freebase.com/api/service/mqlread?queries";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "$apiendpoint=$jsonquerystr");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$jsonresultstr = curl_exec($ch);
curl_close($ch);
$resultarray = json_decode($jsonresultstr, true); #true:give us the json struct as an array
foreach($resultarray as $name){
echo "$name<br>";
}
错误:
{ "code": "/api/status/error", "messages": [ { "code": "/api/status/error", "message": "'list' 对象没有属性 'get'" } ],“状态”:“500 内部错误”,“transaction_id”:“缓存;cache04.p01.sjc1:8101;2012-05-14T07:31:39Z;0079”}