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 SkipVought 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
Oct 9, 2002
158
0
0
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.
 
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.
 
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