Display Top Search Results from Sphider Search as Links

This mashup uses mySQL query code directly from the Sphider Search Engine application and a sample database output script from W3 Schools.

<?php
# [REF_URL: http://www.w3schools.com/PHP/php_mysql_select.asp]
$con = mysql_connect("localhost","USERNAME","PASSWORD");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
mysql_select_db("DATABASE", $con);
# $result = mysql_query("SELECT * FROM query_log");
$result=mysql_query("select query, count(*) as c, date_format(max(time), '%Y-%m-%d %H:%i:%s'), avg(results)  from ".$mysql_table_prefix."query_log group by query order by c desc");
echo "<table border='0'>
<tr>
<th>Keyword(s) by Frequency</th>
</tr>";
while($row = mysql_fetch_array($result))
  {
$term=$row['query'];
  echo "<tr>";
  echo "<td>" . "<a href=\"./path/to/search.php?query=$term&search=1\">" . $row['query'] . "</a>" . "</td>";
  echo "</tr>";
  }
echo "</table>";
mysql_close($con);
?>

Supply your database login credentials marked in green. Create a new variable $term. Insert ‘$term’ as part of the URL for tabular entries.

Advertisements

Tags: ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s


%d bloggers like this: