我正在使用 Sphinx 构建搜索引擎,但由于我的 PHP 知识有限,我最终无法显示结果。对搜索服务器的请求给了我这个多维数组:
Array
(
[0] => Array
(
[id] => 327919409
[weight] => 3
[attrs] => Array
(
[group_id] => 327919409
[date] => 2013
)
)
[1] => Array
(
[id] => 84811232
[weight] => 2
[attrs] => Array
(
[group_id] => 84811232
[date] => 2013
)
)
[2] => Array
(
[id] => 150252575
[weight] => 2
[attrs] => Array
(
[group_id] => 150252575
[date] => 2013
)
)
[3] => Array
(
[id] => 174947829
[weight] => 2
[attrs] => Array
(
[group_id] => 174947829
[date] => 2013
)
)
[4] => Array
(
[id] => 297809970
[weight] => 2
[attrs] => Array
(
[group_id] => 297809970
[date] => 2013
)
)
[5] => Array
(
[id] => 391669252
[weight] => 2
[attrs] => Array
(
[group_id] => 391669252
[date] => 2013
)
)
)
我需要检索并列出所有 ID 值,我正在尝试使用此代码,但我得到的只是来自 foreach 的 NULL 值:
$query = $_GET['q'];
$index = "test1";
require_once('sphinxapi.php');
//Sphinx
$s = new SphinxClient;
$s->setServer("localhost", 9312);
$s->setMatchMode(SPH_MATCH_ALL);
$s->SetArrayResult(true);
//Search Query
$result = $s->Query($query, $index);
if ($result['total'] > 0) {
foreach ($result['matches'] as $key => $id) {
$ido = $id[$key]->id;
//Get Column
$searchColumn = mysql_fetch_array( mysql_query("SELECT * FROM rasti_failai WHERE ID=$ido") );
//Dump
var_dump($searchColumn);
}
} else {
echo 'No results found';
}
任何纠正我的 foreach 循环的帮助将不胜感激。