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 > Php mysql

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-28-09, 08:23
danny_brazil danny_brazil is offline
Registered User
 
Join Date: Jul 2009
Posts: 19
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
Reply With Quote
  #2 (permalink)  
Old 07-28-09, 08:31
danny_brazil danny_brazil is offline
Registered User
 
Join Date: Jul 2009
Posts: 19
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 ?
Reply With Quote
  #3 (permalink)  
Old 07-28-09, 08:57
danny_brazil danny_brazil is offline
Registered User
 
Join Date: Jul 2009
Posts: 19
I got it

thanks anyways

Danny
Reply With Quote
  #4 (permalink)  
Old 07-28-09, 08:59
mike_bike_kite mike_bike_kite is offline
vaguely human
 
Join Date: Jun 2007
Location: London
Posts: 2,519
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>";
     } 
}
Reply With Quote
  #5 (permalink)  
Old 07-28-09, 09:21
danny_brazil danny_brazil is offline
Registered User
 
Join Date: Jul 2009
Posts: 19
Thanks

Thanks dude.

I will search more about it

Thanks again
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