Jump to content

[SOLVED] Mysql SELECT question...


nightkarnation

Recommended Posts

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

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 ?

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

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"
}

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!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.