Skip to content

Instantly share code, notes, and snippets.

@larikraun
Created February 11, 2017 18:20
Show Gist options
  • Save larikraun/68847e9352f9f3c2ba821852ca591e11 to your computer and use it in GitHub Desktop.
Save larikraun/68847e9352f9f3c2ba821852ca591e11 to your computer and use it in GitHub Desktop.
<?php
mysql_connect("localhost", "root", "yourpassword");
mysql_select_db("test");
require_once('sphinxapi.php');
$s = new SphinxClient;
$s->setServer("127.0.0.1", 9312); // NOT "localhost" under Windows 7!
$s->setMatchMode(SPH_MATCH_ANY);
$s->SetLimits(0, 25);
$q=$_GET["q"];
$result = $s->Query($q);
if ($result['total'] > 0) {
echo 'Total: ' . $result['total'] . "<br>\n";
echo 'Total Found: ' . $result['total_found'] . "<br>\n";
echo '<table>';
echo '<tr><td>No.</td><td>ID</td><td>Group ID</td><td>Group ID 2</td><td>Date Added</td><td>Title</td><td>Content</td></tr>';
foreach ($result['matches'] as $id => $otherStuff) {
$row = mysql_fetch_array(mysql_query("select * from documents where id = $id"));
extract($row);
++ $no;
echo "<tr><td>$no</td><td>$id</td><td>$group_id</td><td>$group_id2</td><td>$date_added</td><td>$title</td><td>$content</td></tr>";
}
echo '</table>';
} else {
print $s->GetLastError();
echo 'No results found';
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment