Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

search problems?

Status
Not open for further replies.

JamesGMills

Programmer
Aug 15, 2005
157
GB
Problem:

Search string
Code:
$s = $_GET['s'];
could be something like
Code:
france, white

then i have

Code:
SELECT *, date_format(item_dateAdded, '%D %M %Y') as item_dateAdded FROM items WHERE 
	 item_name LIKE '$s' OR item_country LIKE '$s' OR item_type LIKE '$s' OR item_subtype LIKE '$s'

But the problem is i need to split the $s up because there is two workds to search for but this just confuses the search?

How do you do this?

Ahhhhhhhhhgggrrrrrr....
 
FIrst of all, this is more a SQL question than a PHP question.
Anyway, here are some pointers:

1. You have to decide what you want to split on - it appears it is the comma.
2. Have a look at the explode() function in the PHP manual. It will put the search arguments into an array.
3. Iterate the array with foreach() and construct the search SQL.

It might also be helpful to use the percent wildcards in the SQL to make sure that the search term found also if it is within a string, not just at the beginning.

Hope that helps.
 
Interesting - yes thats enough to get me started on looking into the solution - thank you :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top