I'm building search engine with Sphinx, but I'm stuck at the end with displaying results as my PHP knowledge is limited. The request to search server gives me this multi dimensional array:
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
)
)
)
I need to retrieve and list all ID values, I'm trying to use this code but all I get is NULL values from the foreach:
$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';
}
Any help correcting my foreach loop would be really appreciated.