Results 1 to 4 of 4
  1. #1
    Join Date
    Jul 2009
    Posts
    23

    Unanswered: 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 ?

  2. #2
    Join Date
    Jul 2009
    Posts
    23

    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

  3. #3
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    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 )
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  4. #4
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    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 on the Tiger 800 or the Norton

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •