Page 1 of 1

query

Posted: Wed Dec 15, 2004 6:46 am
by gurjit
Hi all,

simple but i just cant get my brain to function.

I have a field of locations, when i search lets say for example "london", i have london stored as "london *" in the database with "*", how can i find london, so i want to only find characters with [a-z] or [A-Z] or [0-9], missing out any special characters in the where statement

select * from tbl_location where lname = '$location'

Posted: Wed Dec 15, 2004 6:51 am
by qads

Code: Select all

<?php
preg_match("([A-Za-z0-9\s]+)", $row['location'], $match);
$location = $match[0];
?>
above will match a-z,A-Z,0-9 and spaces :).

Posted: Wed Dec 15, 2004 7:02 am
by gurjit
In the query this not work.....

i want to be able to put in the search box "london" and in the where clause say something with a wild card to miss out the "*" in "london *", which is how it is stored in the database.

Posted: Wed Dec 15, 2004 7:11 am
by qads
above code is not meant to be used in the query, use it after you fetch the results to show only city names.

try:

Code: Select all

<?php
$query = "select city from table where cityname LIKE '%$searchfield%'";
?>