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!

Problems with LIKE statement

Status
Not open for further replies.

paulbradley

Programmer
Joined
Oct 9, 2002
Messages
158
Location
GB
I have a search box which users can enter a phrase and it searches for items LIKE what they enetered, using the following command:

SELECT product_name FROM products WHERE '$searchitem' LIKE product_name ORDER BY end_time

But this only seems to return items identical to product_name. Any ideas? Thanks in advance.
 
you need to add "wildcards" to the search term and reverse the order.

... WHERE product_name LIKE " . "'%" . $searchitem . "%'" . " ORDER...

Chris.

Indifference will be the downfall of mankind, but who cares?
Woo Hoo! the cobblers kids get new shoes.
Nightclub counting systems

So long, and thanks for all the fish.
 
That dosen't seem to help I'm afraid, it's only returning items which *exactly* match what i entered.

Thanks for the help so far.
 
which rdbms are you using?
 
sorry ... and are you using an abstraction layer?
 
Using mysql db, your query look like this in php:

Code:
$query = "SELECT product_name FROM products WHERE $searchitem LIKE '%$product_name%' ORDER BY end_time";

remove the '' near $searchitem but add them for $productname.

Tell us if it works!
 
Code:
SELECT product_name FROM products WHERE product_name LIKE '%$searchitem%' ORDER BY end_time

or
Code:
SELECT product_name FROM products WHERE '$searchitem' LIKE '%product_name%' ORDER BY end_time

otherwise I don't know what you mean ???
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top