Jump to content

[SOLVED] MySQL Search Engine problem...


gabarab

Recommended Posts

Hello. I am currently working on a website, and it needs a search engine.

The current code i am using is:

 

if(isset($_REQUEST['search_msgs'])) {
   if(isset($_REQUEST['searchall'])) { 
$searching = strtoupper($_POST['searching']);
$searching = strip_tags($searching);
$searching = trim ($searching); 
$query = "select * from ****** where upper(message) like '%$searching%' order by posted DESC";
}
   else {
$searching = strtoupper($_POST['searching']);
$searching = strip_tags($searching);
$searching = trim ($searching); 
$select_category=$_POST['select_category'];
$query = "select * from ****** where message like '%$searching%' AND category='$select_category' order by posted DESC";
}
}
else {
$query="SELECT * FROM ****** where category='$showall' order by posted DESC";

$getmsg = mysql_query("$query") or die(mysql_error()

 

The code works perfectly for single word search..."word"

but i need to add the possibility to search by multiple words.

Now, if I search for "some word" the search will be made only for "word"...

I know it should be something that will include explode()  but i don't know how to add to the query every word inserted.

Can someone please help me with my problem?

Thank you in advance.

Link to comment
Share on other sites

if you search for "LIKE '%some word%' " every row that is fetched should have "some word" in it. Are you saying that if a user types "some word" that you want it to search for both "some" and "word" separately? Or do you wanna just make sure the rows searched have both "some" and "word" but not necessarily next to eachother?

Link to comment
Share on other sites

if you search for "LIKE '%some word%' " every row that is fetched should have "some word" in it. Are you saying that if a user types "some word" that you want it to search for both "some" and "word" separately? Or do you wanna just make sure the rows searched have both "some" and "word" but not necessarily next to each other?

I haven't worked with foreach() so far... did not need it, i guess...

I want to search for both some and word from the input, but, as you said, not necessarily next to each other.

my problem is that i haven't the slightest idea on how to make it.

I suppose that

foreach($keywords as $keyword){
     $sql .=  " AND  keyword LIKE '%$keyword%'";
}

would work...i just don't know how to implement it in to my script :(

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.