SEARCH HELP

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
gurjit
Forum Contributor
Posts: 314
Joined: Thu May 15, 2003 11:53 am
Location: UK

SEARCH HELP

Post 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?
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

This should work:

Code: Select all

SELECT
   *
FROM
   myTable
WHERE
   postcode LIKE '%user_entered_string%'
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post 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.
Post Reply