How to amend this mysql 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
hm9
Forum Newbie
Posts: 14
Joined: Sun May 09, 2010 4:27 pm

How to amend this mysql query

Post by hm9 »

Hi

I have a condition in PHP that checks if a user select an airport from a drop down menu , the results should be entries that matches that airport, but i want to amend it so that if a user selects, All London Airports, it should yield entries fro london stansted, london gatwick, london city and heathrow. I managed to get it to work with one condition but not sure how to get it to work with many entries. The code below works but can you advise how to amend it to include other london airports.
if($depoint=='London All Airports') {
$sql .= ' AND departurepoint= ("London Gatwick")'; }

else {

$sql .= ' AND departurepoint = "'.$depoint.'"'; }

.
[/syntax]


Note: $depoint is the variable that stores users selection
Departurepoint is the column name in the table


Thanks in advance
mikosiko
Forum Regular
Posts: 757
Joined: Wed Jan 13, 2010 7:22 pm

Re: How to amend this mysql query

Post by mikosiko »

assuming that all your "London" airports names start with "London" you can use LIKE

as "AND departurepoint LIKE '%London%' "
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: How to amend this mysql query

Post by Eran »

LIKE '%London%'
Will match all entries that have the word London in it (not just at the beginning) and can't use an index. If you want to match just entries that start with 'London', put the wildcard only at the end:

Code: Select all

AND departurepoint LIKE 'London%'
mikosiko
Forum Regular
Posts: 757
Joined: Wed Jan 13, 2010 7:22 pm

Re: How to amend this mysql query

Post by mikosiko »

I knew that to much drink last night will get me today :? :oops:
hm9
Forum Newbie
Posts: 14
Joined: Sun May 09, 2010 4:27 pm

Re: How to amend this mysql query

Post by hm9 »

thanks guys
Post Reply