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, Link to comment https://forums.phpfreaks.com/topic/124550-solved-mysql-select-question/ 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? Link to comment https://forums.phpfreaks.com/topic/124550-solved-mysql-select-question/#findComment-643279 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. Link to comment https://forums.phpfreaks.com/topic/124550-solved-mysql-select-question/#findComment-643288 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 Link to comment https://forums.phpfreaks.com/topic/124550-solved-mysql-select-question/#findComment-643293 Share on other sites More sharing options...
DarkWater Posted September 16, 2008 Share Posted September 16, 2008 That just adds more work for MySQL. Link to comment https://forums.phpfreaks.com/topic/124550-solved-mysql-select-question/#findComment-643294 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 ? Link to comment https://forums.phpfreaks.com/topic/124550-solved-mysql-select-question/#findComment-643297 Share on other sites More sharing options...
DarkWater Posted September 16, 2008 Share Posted September 16, 2008 Leave out the neighborhood part... Link to comment https://forums.phpfreaks.com/topic/124550-solved-mysql-select-question/#findComment-643298 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 Link to comment https://forums.phpfreaks.com/topic/124550-solved-mysql-select-question/#findComment-643300 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 '%' Link to comment https://forums.phpfreaks.com/topic/124550-solved-mysql-select-question/#findComment-643301 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 Link to comment https://forums.phpfreaks.com/topic/124550-solved-mysql-select-question/#findComment-643312 Share on other sites More sharing options...
unkwntech Posted September 16, 2008 Share Posted September 16, 2008 Yes Link to comment https://forums.phpfreaks.com/topic/124550-solved-mysql-select-question/#findComment-643315 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. Link to comment https://forums.phpfreaks.com/topic/124550-solved-mysql-select-question/#findComment-643317 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" } Link to comment https://forums.phpfreaks.com/topic/124550-solved-mysql-select-question/#findComment-643319 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! Link to comment https://forums.phpfreaks.com/topic/124550-solved-mysql-select-question/#findComment-643329 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.