Page 1 of 1

i want to search all words using "and" not "or" !!!

Posted: Sat Aug 09, 2008 2:12 pm
by lukilukg4
~pickle | Please use [ code=html ], [ code=php ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: :arrow: Posting Code in the Forums to learn how to do it too.


hi

i use this code to search some inserts from mysql... but i would like to search the database taking into consideration all the words
this is a part from my code

Code: Select all

 
//search variable = data in search box or url
if(isset($_GET['search']))
{
$search = $_GET['search'];
}
 
//trim whitespace from variable
$search = trim($search);
$search = preg_replace('/\s+/', ' ', $search);
 
//seperate multiple keywords into array space delimited
$keywords = explode(" ", $search);
 
//Clean empty arrays so they don't get every row as result
$keywords = array_diff($keywords, array(""));

I think that in this part of my code is the problem

can u help me plz to solve it...

tnx



~pickle | Please use [ code=html ], [ code=php ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: :arrow: Posting Code in the Forums to learn how to do it too.

Re: i want to search all words using "and" not "or" !!!

Posted: Sat Aug 09, 2008 9:00 pm
by califdon
What is the problem you are trying to solve? You haven't shown us any of the query code. If you do post more code, please enclose it in [syntax=php]...[/syntax] tags to make it easier for us to read.

Re: i want to search all words using "and" not "or" !!!

Posted: Sat Aug 09, 2008 9:19 pm
by lukilukg4
i am using this code by shane.... when i am searching for e.g. Nick Brown it searches Nick or Brown. i want to seacrh Nick and Brown... Am i clear now? Sorry if i wasnt clear from the beginning


The link is http://www.hackosis.com/2007/11/06/howt ... and-mysql/


tnx

Re: i want to search all words using "and" not "or" !!!

Posted: Sat Aug 09, 2008 10:05 pm
by califdon
We will need to know a lot more in order to help you. What is the structure of the database table? Does it have one field in which you expect to find the string "Nick Brown" or does it have fields for first and last names? How are you obtaining the search string(s)? One form field? What is the SQL Query that you are using?

Re: i want to search all words using "and" not "or" !!!

Posted: Sat Aug 09, 2008 10:31 pm
by lukilukg4
well

i have in mysql's table: columm1 columm2 columm3 columm4

columm1 has---> 1.Nick Brown
2. Nick Black
3. George Brown
4.John Best


columm2 ----> we dont care.......

when i am using this code and i am searching Nick Brown the result is...

Nick Brown
Nick Black
George Brown


this means that it searches Nick or Brown

I want to search Nick and Brown... I want to take only the insert

Nick Brown


I hope to explain better this time