Jump to content

[SOLVED] How to SELECT records WHERE field contains a particular string?


stephfox

Recommended Posts

Hi,

I need to SELECT records WHERE a string matches the content of a field...

 

eg. I have field values like:

 

  • Phone name
  • Phone name pink
  • Phone name blue
  • Phone name polka-dot

 

What I want is to have a MySQL query which selects ALL records which match the search term, eg. 'Phone name' returns all of the above, but not 'Phone':

 

Currently my query looks like this:

SELECT * FROM [table_name] WHERE [field_name] LIKE '%s' ORDER BY [value] ASC

 

I'm sure this is easy, but can't get there myself.. Help!

Any ideas?

Thanks,

S

Thanks for your help...

 

I've solved this problem now, the error was that the query was being built into an sprintf() function, and then executed... I was trying to figure out what the '%s' part of the query was doing.

 

Sprintf won't allow any % signs to be included in the query string as wildcards, and was causing the error...

I've now built the query as a simple string variable, and now I can happily add in the % for the LIKE clause, and all works fine!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.