Make a table for the frequently most searched keywords and the content for those keywords.
CREATE TABLE `your_database`.`content` (
`id` INT PRIMARY KEY AUTO_INCREMENT ,
`content` TEXT NOT NULL ,
`keywords` VARCHAR( 500 ) NOT NULL,
) ENGINE = MYISAM ;
CREATE TABLE `your_database`.`most_searched` (
`term` VARCHAR( 50 ) NOT NULL ,
`times` INT ,
) ENGINE = MYISAM ;
<?php
$q = $_GET['q'];
$term= explode(" ", $q); //SPLITS EACH TERM BY A SPACE for($i=0; $i<count($term); $i++){ if($i==0){ $m.="term='".$term[$i]."'"; $t.="keywords='".$term[$i]."'";
}
else
{ $m.=" AND term='".$term[$i]."'"; $t.=" OR keywords='".$term[$i]."'";
}
}
//CHECKS IF ANY KEYWORDS EXIST IN ANY CONTENT
mysql_connect("server", "username", "password"); $query= mysql_query("SELECT * FROM your_database.content WHERE $t"); $n= mysql_num_rows($query);
//IF SO, UPDATE THE NUMBER OF SEARCHES FOR EACH TERM
if($n){ $query= mysql_query("SELECT * FROM your_database.most_searched WHERE $m"); $r= mysql_fetch_assoc($query); $times = $r['times']; $add = $times+1; mysql_query("UPDATE your_database.most_searched SET times='$add' WHERE $m");
}
//LISTS THE MOST SEARCHED TERMS
$query= mysql_query("SELECT * FROM your_database.most_searched ORDER BY times DESC LIMIT 0, 5"); //SHOWS THE TOP 5 while($r=mysql_fetch_array($query)){ $fms .= $r['term'];
} echo$fms.' ';