Page 1 of 1

SEARCH HELP

Posted: Tue Nov 29, 2005 10:14 am
by gurjit
Hi all,

I have a postcode field which i need to search on to find any postcodes that match the users search.

The postcode is seperated by commas for each record.

e.g.

postcode
W10,W11,W2,W3

how can i do this?

Posted: Tue Nov 29, 2005 12:07 pm
by pickle
This should work:

Code: Select all

SELECT
   *
FROM
   myTable
WHERE
   postcode LIKE '%user_entered_string%'

Posted: Tue Nov 29, 2005 12:13 pm
by Burrito
if the commas separate potential values on the db, you can use "IN" in your search query:

Code: Select all

$query = "select * from myTable where someField IN(".$_POST['somePostField'].")";
if you're searching strings...which it looks like you are, you'll need to throw single quotes around each "value".

let me know if you need help with that.