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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
lukilukg4
Forum Newbie
Posts: 12
Joined: Wed Jul 23, 2008 2:51 pm

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

Post 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.
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

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

Post 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.
lukilukg4
Forum Newbie
Posts: 12
Joined: Wed Jul 23, 2008 2:51 pm

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

Post 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
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

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

Post 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?
lukilukg4
Forum Newbie
Posts: 12
Joined: Wed Jul 23, 2008 2:51 pm

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

Post 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
Post Reply