Link to home
Start Free TrialLog in
Avatar of jws2bay
jws2bay

asked on

MySQL statement using LIKE

I am working on a mySQL/PHP web server.   I currently have the following statement:

"SELECT * FROM Products WHERE Part_no LIKE %s ORDER BY Finish ASC", GetSQLValueString($colname_RS_group . "%", "text")

It is sorting data with Part_no similar to:

SDCD38CH
SDCD38CHK
SDCD38PB
SDCD12CH

The search term pulled from the URL is SDCD38.   The result I currently get is:

SDCD38CH
SDCD38CHK
SDCD38PB

I want to filter out any Part_no ending in K so that I get

SDCD38CH
SDCD38PB

How can I modify the LIKE term to block any Part_no ending in K?
ASKER CERTIFIED SOLUTION
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
And of course, never, never, NEVER use "SELECT *" in production code

Why? Just figure that your select * works fine on your table with 10 fields of at most 10 bytes each, and that at a later stage one field is added with variable length more than 10K on average (eg, text from a web page or image)... everybody will be puzzled at the sudden drop in performance (best case) or time-out on script (frequent), or (worse) a db ctash...
Avatar of jws2bay
jws2bay

ASKER

Bernard,

Agreed.   I'll get it down to the specific field after I have the page working.

Any ideas how to write a LIKE and does not end with K?
Avatar of jws2bay

ASKER

Ryan,  That's it - works like it should.       Thank you for the help.

Bernard,  Thanks for the comment.