query

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

query

Post 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'
qads
DevNet Resident
Posts: 1199
Joined: Tue Apr 23, 2002 10:02 am
Location: Brisbane

Post 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 :).
User avatar
gurjit
Forum Contributor
Posts: 314
Joined: Thu May 15, 2003 11:53 am
Location: UK

Post 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.
qads
DevNet Resident
Posts: 1199
Joined: Tue Apr 23, 2002 10:02 am
Location: Brisbane

Post 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%'";
?>
Post Reply