If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > between (prices)

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-26-09, 07:05
danny_brazil danny_brazil is offline
Registered User
 
Join Date: Jul 2009
Posts: 19
between (prices)

Hello
Im trying to get from my database only the data that is within the range typed by the user
for example :

price range :
_________ till ______________

lets say the user typed : 10,000 till 30,000

now in the data base there is JUST the price of the house.

what will be the php query code in this case?

i was trying something like :
Code:
SELECT * FROM $tbl_name WHERE cidade='$cidade' AND bairro='$bairro' AND category='$category' AND quartos='2'||'3' AND preco<='$preco2' || <='$preco1'
the important part is : AND '$preco1'>=preco<='$preco2'

any help ? Thanks a lot

Danny

p.s.
as well i wanted to know if the query in general is ok
will it show the user only the data base entries between the price range ?
Reply With Quote
  #2 (permalink)  
Old 07-26-09, 08:21
danny_brazil danny_brazil is offline
Registered User
 
Join Date: Jul 2009
Posts: 19
i tried also

i tried also
Code:
$data = mysql_query("SELECT  * FROM _Form_Nr_2 WHERE preco BETWEEN '$preco1' AND '$preco2' ") or die(mysql_error());

but still nothing
Reply With Quote
  #3 (permalink)  
Old 07-26-09, 08:49
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
please use mysqldump (or equivalent) to produce a CREATE TABLE statement along with several INSERT statements that will have data that illustrates your scenario

this will allow us to test your query on your data to investigate why it isn't working

by the way, this is totally wrong --
Code:
AND quartos='2'||'3'
what you want is this instead --
Code:
AND quartos IN ( 2 , 3 )
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #4 (permalink)  
Old 07-26-09, 15:14
healdem healdem is offline
Jaded Developer
 
Join Date: Nov 2004
Location: out on a limb
Posts: 9,258
assuming preco is numeric and the preco1/2 is also numeric ie has no punctuation, then you don't need the '

SELECT * FROM _Form_Nr_2
WHERE preco BETWEEN $preco1 AND $preco2;") or die(mysql_error());
__________________
I'd rather be riding my Versys or my Tiger 800 let alone the Norton
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On