You are here:  » Top search problems

Support Forum



Top search problems

Submitted by pat on Fri, 2007-05-18 18:17 in

Hello

I tried to add a "top search" on my pages like on header.php but I keep getting this type of error:

Warning
: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in
...\includes\database.php

** I followed all steps from the thread 892, created the table and queries are logged ok, i have no table prefix in config.php, and I can't get it to work.

I tried to create a file "top_search.php" with :

<?php
  
print "<p>Top Searches</p>";
  print 
"<ul>";
  
$sql "SELECT * FROM querylog ORDER BY count DESC LIMIT 10";
  if (
database_querySelect($sql,$rows))
  {
    foreach(
$rows as $row)
    {
      
$url $config_baseHREF."search.php?q=".urlencode($row["query"]);
      print 
"<li><a href='".$url."'>".$row["query"]."</a></li>";
    }
  }
  print 
"</ul>";
?>

on header.php (or other pages) I call the file with an include:

<?php
 
include('top_search.php'); 
?>
or i copy the whole stuff directly on the page, no matter what I do i always get the same error

Any idea what could be wrong?

Thanks

Pat

Submitted by support on Thu, 2007-05-24 12:14

Hello Pat,

I think the problem may be that count is a reserved word and so will have to be enclosed in back-ticks within the SQL. Try this:

  $sql = "SELECT * FROM querylog ORDER BY `count` DESC LIMIT 10";

Cheers,
David.