Results 1 to 5 of 5

Thread: Php mysql

  1. #1
    Join Date
    Jul 2009
    Posts
    23

    Unanswered: Php mysql

    Hello there

    Im trying to create an sql that will quire some data from my data base

    the form link is : Meu-ape

    and the sql code is :
    Code:
    $and='AND';
    
    //category
    $category="category='$category' ";
    
    //cidade
    $cidade='cidade="$cidade"';
    
    //bairro
    $bairro='bairro="$bairro"';
    
    //quartos = Tudo
    $quartos_tudo="quartos IN ('1','2','3','4','Kitinet')";
    
    //preco between
    $preco_between="preco_between BETWEEN '$preco1' AND '$preco2'";
    
    if($quartos=="Tudo")
    {
    $data = mysql_query("SELECT  * FROM _Form_Nr_2 WHERE $preco_between $and $quartos_tudo $and $bairro $and $cidade $and $category") or die(mysql_error());
    }
    quartos = Tudo (that is how im trying it...it mean ...the user chooses all rooms..all the options)

    any help ?

    Danny

  2. #2
    Join Date
    Jul 2009
    Posts
    23

    even more

    I noticed that even this one doesnt work

    Code:
    if($quartos=="Tudo")
    {
    $data = mysql_query("SELECT  * FROM _Form_Nr_2 WHERE  $cidade AND $preco_between ") or die(mysql_error());
    }

    any help ?

  3. #3
    Join Date
    Jul 2009
    Posts
    23
    I got it

    thanks anyways

    Danny

  4. #4
    Join Date
    Jun 2007
    Location
    London
    Posts
    2,527
    It will be more helpful if you print out the SQL before you run it. That way you might even spot the error yourself. It might even be worth showing us what the error is. A few points though.
    • mysql_query doesn't return data
    • select * will return multiple fields not one field
    • you are likely to get more than one row returned
    • if you use single quotes then variables won't be translated
    • even in Spanish (?) your table names look bad
    • what happens if a value hasn't been entered for a field
    Something like the following would work better but I can't test it on my end. I'd suggest reading a book or looking at a few web sites on PHP / MySQL:
    Code:
    if($quartos=="Tudo") {
        $sql = "SELECT * 
               FROM    _Form_Nr_2 
               WHERE   preco_between BETWEEN '$preco1' AND '$preco2'
                       and quartos IN ('1','2','3','4','Kitinet')
                       and bairro='$bairro'
                       and cidade='$cidade' 
                       and category='$category' ";
    
         $result = mysql_query( $sql ) or die(mysql_error());
    
         while($row = mysql_fetch_array($result, MYSQL_NUM)) {
             echo $row[0] . " " . $row[1] . " " . $row[2] . "<br>";
         } 
    }

  5. #5
    Join Date
    Jul 2009
    Posts
    23

    Thanks

    Thanks dude.

    I will search more about it

    Thanks again

Posting Permissions

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