Use Full text search :
<?PHP
//SET THE SEARCH TERM
$term = "Search Term";
$sql = "SELECT *, MATCH(subject, message,reference,textbody) AGAINST('". $term ."') as score FROM pages WHERE MATCH (subject, message,reference,textbody) AGAINST('". $term ."') ORDER BY score DESC";
$query = mysql_query($sql);
//BUILD A LIST OF THE RESULTS
while($result = mysql_fetch_assoc($query)) {
// your stuff for showing result
}
?>
Note: you should have FULLTEXT
indexing on the columns subject, message,reference,textbody
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…