Posted by:
stevenmartin99
(---.b-ras1.blp.dublin.eircom.net)
first of all- u need wampserver2.0 for this to work because you need mysql new version
yout table in mysql needs to be using the MyISSAM engine fr storage
Then in phpmyadmin open ur table clicj SQL at the top and type this in and pres go
ALTER TABLE informartion ADD FULLTEXT(title);
this allows the column title to be search for single words
underneath is the script i used. iv commented it a much as possible so you can see how it works.
i used match against.
<?php
$search= $_GET['search']; //take the value from the form
MySQL_connect("localhost", "root"
; //connect to mysql
MySQL_select_db("search"
; //connect to database
$searchwords = explode(" ","$search"
; //change the search into an array of
//words and make it a new variable array
foreach ($searchwords as $word) //loop through the words
{
$searchstring= $searchstring.' +'.$word; //add each word in the array to end of a new string
} //so that the string reads
//in the format "+word1 +word2 +word3 etc"
$query = "SELECT * from information where MATCH(title)
AGAINST ('$searchstring' IN BOOLEAN MODE)";
//make a varabile to take any row containing
// the string of words in any order
$result = MySQL_query($query); //query the database with this varible
if(!$result) { //if the varible is not set
echo MySQL_error()."<br>$query<br>"; //cause an error
}
if(MySQL_num_rows($result) > 0){ //if there is data
echo "<table border=1 >"; //make a table
echo "<tr><td>Data </td><td>Title</td></tr>";
while($row = MySQL_fetch_array($result)) { //loop thruogh the rows given back
echo "<td>{$row['data']}</td>"; //display each row of the database containing the searched words
echo "<td>{$row['title']}</td></tr>"; //display each row of the database containing the searched words
}
echo "</table>";
}
else {
echo "No Results were found.<br>"; //if nothing was returned print this
}
echo "<br>";
?>
hope this helps
steven
Edited 3 time(s). Last edit at 02/17/2008 09:44AM by stevenmartin99.