nightkarnation Posted September 16, 2008 Share Posted September 16, 2008 Hello, i was wondering what goes where i wrote *...in the following SQL Query SELECT * FROM `apt_data` WHERE neighborhood = * AND weeklyRate <= 400 What i want is to query ALL the neighborhoods that are less or equal to 400 (i know that simply without placing neighborhood i will query it) but this comes from a much larger code connected to php/flash and i need to know how can i specify neighborhood = ALL/EVERY NEIGHBORHOOD on this query... Thank u very much in advance! Cheers, Quote Link to comment Share on other sites More sharing options...
DarkWater Posted September 16, 2008 Share Posted September 16, 2008 #sql SELECT * FROM apt_data WHERE weeklyRate <= 400 That's all you need...what's the problem? Quote Link to comment Share on other sites More sharing options...
unkwntech Posted September 16, 2008 Share Posted September 16, 2008 Dark Water is correct, as is your example. I don't see the problem. Quote Link to comment Share on other sites More sharing options...
scott_m Posted September 16, 2008 Share Posted September 16, 2008 you can always use neighborhood = neighborhood if you already have quotes around it I don't think you can use a wildcard Quote Link to comment Share on other sites More sharing options...
DarkWater Posted September 16, 2008 Share Posted September 16, 2008 That just adds more work for MySQL. Quote Link to comment Share on other sites More sharing options...
nightkarnation Posted September 16, 2008 Author Share Posted September 16, 2008 The thing is that this query recieves information from flash/php... the real one is: SELECT * FROM `apt_data` WHERE neighborhood = '$neighborhood' AND weeklyRate <= 400 And there's an option on flash that says: ALL NEIGHBORHOODS ... instead of a specific neighborhood...so how can i tell to the query to look for All Neighborhoods ? Quote Link to comment Share on other sites More sharing options...
DarkWater Posted September 16, 2008 Share Posted September 16, 2008 Leave out the neighborhood part... Quote Link to comment Share on other sites More sharing options...
scott_m Posted September 16, 2008 Share Posted September 16, 2008 Sounds like you're going to have to put in conditional statements to change the query based on the user input Quote Link to comment Share on other sites More sharing options...
unkwntech Posted September 16, 2008 Share Posted September 16, 2008 If you have a field for 'all' as opposed to a specific neighborhood, (i.e. a real estate search, where I dont care what neighborhood as long as its in the correct city) then just set $neighborhood to '%' Quote Link to comment Share on other sites More sharing options...
nightkarnation Posted September 16, 2008 Author Share Posted September 16, 2008 unkwntech do u mean this: SELECT * FROM `apt_data` WHERE neighborhood = '%' AND weeklyRate <= 400 ? DarkWater ur not getting it, sorry for not being so clear... On flash i have a Neighborhood combobox that has 4 options... ALL NEIGHBORHOODS Belgrano Palermo San Telmo Now...if a user selects Belgrano then... SELECT * FROM `apt_data` WHERE neighborhood = '$neighborhood' AND weeklyRate <= 400 works perfectly... But if the user selectds ALL NEIGHBORHOODS...how can i tell $neighborhood before the query to = something that equals all neighborhoods Quote Link to comment Share on other sites More sharing options...
unkwntech Posted September 16, 2008 Share Posted September 16, 2008 Yes Quote Link to comment Share on other sites More sharing options...
DarkWater Posted September 16, 2008 Share Posted September 16, 2008 This is why they made if statements, nightkarnation. Quote Link to comment Share on other sites More sharing options...
unkwntech Posted September 16, 2008 Share Posted September 16, 2008 As its been pointed out this is a better solution the using % if($_POST['neighborhood'] == 'all') { $sql = "SELECT * FROM `apt_data` WHERE weeklyRate <= 400"; } else { $sql = "SELECT * FROM `apt_data` WHERE neighborhood = '$neighborhood' AND weeklyRate <= 400" } Quote Link to comment Share on other sites More sharing options...
nightkarnation Posted September 16, 2008 Author Share Posted September 16, 2008 Ok! thank you very much unkwntech and darkwater... U have been very helpul...yes i was aware of the IF statement, though i wanted to know if there was a way to solve this directly in the same query, anyway IF aint bad at all, just 2 more lines of code, Thanx again! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.