No need to post in the PHP forum as you can do this all from within MySQL. There are a few different methods too.
Method 1:
Using like, the advantage here is that you can use wildcards ( % )
Code:
SELECT * FROM Apartments WHERE Location LIKE 'Seattle';
Method 2:
Using a more precise method, this method is great when you have a table with specific location names and you have no need to match via a pattern of some sort.
Code:
SELECT * FROM Apartments WHERE Location = 'Seattle';
Method 3:
Using Regex, this method is not really neccesary for your needs unless you have need to various strings from disparate backgrounds and you have no clue what may be thrown at you next or if you want to match several locations in a more precise manner than the LIKE clause.
Code:
SELECT * FROM Apartments WHERE Location REGEXP '^Sea';
Method 4:
Full Text Searching, this is more preffered for natural language query type of search engine (like Google). This method also has some scoring options to filter better results from less likely ones however I will just give you the base example for now.
Code:
SELECT *, MATCH('Location') AGAINST('Seattle') FROM Apartments;
|