Jump to content

Searching the database for consecutive words (and combinations)


blaster_god

Recommended Posts

Hello, I posted this message in to a few forums but no one could help me . Maybe I will get lucky here . I want to make a search in my PHP database and return all rows that contain some keywords, one after another, in any order (or at least half of them, one after another) .

I want also to take words that has the key in them .

If we have the word "good" , the word "goodness" will be ok and also "nogood" will be ok .

 

I will explain more below .

I have an array with keywords (the array can have maximum 6 elements) . So :

key[1]="hello"

key[2]="how"

key[3]="snow"

key[4]="dancing"

key[5]="golf"

 

I need a script that will search and return all rows that contain at least 3 (5/2 majored to the largest is 3) of this keywords, one after another, in any order . So something like all combinations :

 

Here hello how snow is fine  -> good

When dancing gold snow how is it ?  -> good

how snow dancing golf is at the mountain .  -> good

I am wondering how snowing dancing golf is.  -> good

Fred says hellow snow  -> not good (only 2 words)

 

 

So far I am using :

 

$mysql_str='%';
for($i=0;$i<$no;$i++)
$mysql_str=$mysql_str.'%'.$keyword[$i];
$mysql_str=$mysql_str.'%';

->this is to add all words in a string for the mysql query

 

$result=mysql_query("SELECT *FROM `articole2` WHERE `continut` LIKE '$mysql_str' ORDER BY RAND() LIMIT 1001;");

->this is to return the results .

 

The problem is that my script returns results that have all words, anywhere in the body of the row . I need it to work only in consecutive order . Is it possible ?

I know this is hard ... but maybe someone can help . Thank you in advance

Link to comment
Share on other sites

Hello, I already looked there .. but I diden't find any method of doing what I want . I am not very good with mysql . This is a part of a software (.exe) that I am making for a contest for my school . I am good with C++ ... not with php and mysql ..

Please someone help me with this . Thank you

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.