Page 1 of 1

How to amend this mysql query

Posted: Sun May 23, 2010 3:22 pm
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

Re: How to amend this mysql query

Posted: Sun May 23, 2010 4:21 pm
by mikosiko
assuming that all your "London" airports names start with "London" you can use LIKE

as "AND departurepoint LIKE '%London%' "

Re: How to amend this mysql query

Posted: Sun May 23, 2010 4:35 pm
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%'

Re: How to amend this mysql query

Posted: Sun May 23, 2010 4:38 pm
by mikosiko
I knew that to much drink last night will get me today :? :oops:

Re: How to amend this mysql query

Posted: Mon May 24, 2010 7:39 am
by hm9
thanks guys