mysql match() against() not working
Posted by: john787787 (---.hsd1.co.comcast.net)
Date: February 15, 2008 06:30PM

The mysql match and against functions appear to not be working. I receive an error when I try to use the query below. Here is the code that I am using:


$search = $_GET['search']
$data = mysql_query("SELECT * FROM information WHERE MATCH(title) AGAINST('$search' IN BOOLEAN MODE)"winking smiley;


Is there anything wrong with this code, or is there a way to enable match and against?

Thank you.

Options: ReplyQuote
Re: mysql match() against() not working
Posted by: stevenmartin99 (---.b-ras1.blp.dublin.eircom.net)
Date: February 15, 2008 06:37PM

your selecting everything from a table then u have a refinment? seems strange to do that and i sunno if u can do that


wat exactly are u trying to get from database as iv never needed to use match or against and iv done some complicated selects

Options: ReplyQuote
Re: mysql match() against() not working
Posted by: john787787 (---.hsd1.co.comcast.net)
Date: February 15, 2008 06:44PM

I'm not too familiar with mysql, so there may be some minor problems. I am trying to allow someone to enter search terms and then have mysql return a table based on their search.

Should I use something other than match and against to perform this query?

I had been using:

mysql_query("SELECT * FROM information WHERE title = '$search'"winking smiley;

but this wouldn't allow anyone to enter more than one term and return with a result in the opposite order:


search entry : "one two" would not return something with the title: "two one"

Options: ReplyQuote
Re: mysql match() against() not working
Posted by: stevenmartin99 (---.b-ras1.blp.dublin.eircom.net)
Date: February 15, 2008 06:51PM

$result = mysql_query("SELECT * FROM information WHERE a='$a' && b='$b' "winking smiley


this will return any row of info that has both in it


maybe ur information is not well stored in database...

Options: ReplyQuote
Re: mysql match() against() not working
Posted by: john787787 (---.hsd1.co.comcast.net)
Date: February 15, 2008 06:59PM

That would work if each row had one word or value in each column.

In the column named title, there could be a row with the value of "pencil desk"

if someone searches "desk pencil", your method will not return the row with "pencil desk"

I want the result to include every row that contains "desk" and "pencil"

Options: ReplyQuote
Re: mysql match() against() not working
Posted by: stevenmartin99 (---.b-ras1.blp.dublin.eircom.net)
Date: February 15, 2008 07:04PM

well first--- u need to get there search as a string varibile---- spilt it at each gap and strip them , save them as varibles


so like $search would be split into $word1 , $word2 etc etc or use a n array if ur comforablt with them

then use FETCH to fetch the row that contains the both varibles--

this way u wont need to worry abouit the order they write them in



need help - just ask

Options: ReplyQuote
Re: mysql match() against() not working
Posted by: john787787 (---.hsd1.co.comcast.net)
Date: February 15, 2008 07:10PM

I haven't ever heard of the FETCH function.

Could you please tell me how to use it?

Thanks for all of your help.

Options: ReplyQuote
Re: mysql match() against() not working
Posted by: stevenmartin99 (---.b-ras1.blp.dublin.eircom.net)
Date: February 16, 2008 10:44AM

hi actually this took awhile to get working . look at on my server here [86.42.110.251]

is this wat ur looking for?

Options: ReplyQuote
Re: mysql match() against() not working
Posted by: stevenmartin99 (---.b-ras1.blp.dublin.eircom.net)
Date: February 17, 2008 09:33AM

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"winking smiley; //connect to mysql
MySQL_select_db("search"winking smiley; //connect to database


$searchwords = explode(" ","$search"winking smiley; //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.

Options: ReplyQuote
Re: mysql match() against() not working
Posted by: markman (67.32.4.---)
Date: February 20, 2008 05:29PM

stevemartin99 you are the man!!!

by reading ya'll's dialoge I was able to modify my script using yours above.

thank you thank you thank you thank you!! wow. thanks

Options: ReplyQuote
Re: mysql match() against() not working
Posted by: stevenmartin99 (---.b-ras1.blp.dublin.eircom.net)
Date: February 20, 2008 05:40PM

your welcome

Options: ReplyQuote


Sorry, only registered users may post in this forum.