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 > database sql

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-28-09, 15:17
danny_brazil danny_brazil is offline
Registered User
 
Join Date: Jul 2009
Posts: 19
database sql

Hello
im not a pro' but im sure that there is a better way and shorter to get data from my DB according the form (link : Meu-ape)

here is the code :
Code:
//Here we count the number of results 
//Edit $data to be your query 

//category
$category_sql="category='$category' ";

//cidade
$cidade_sql="cidade='$cidade'";

//bairro
$bairro_sql="bairro='$bairro'";

//bairro_Tudo
$bairro_tudo="bairro IN ('Lagoa Nova','Tirol')";

//quartos = Tudo
$quartos_tudo="quartos IN ('1','2','3','4','Kitinet')";

//quartos
$quartos_sql="quartos='$quartos' ";

//preco between
$preco_between="preco_between BETWEEN '$preco1' AND '$preco2'";


// now the SQL
if($quartos=="Tudo"&&$bairro=="Tudo"&&$preco1==""&&$preco2=="")
{
$data = mysql_query("SELECT  * FROM _Form_Nr_2 WHERE  $category_sql AND $cidade_sql AND $bairro_tudo AND $quartos_tudo") or die(mysql_error());
}
elseif($quartos=="Tudo"&&$bairro=="Tudo")
{
$data = mysql_query("SELECT  * FROM _Form_Nr_2 WHERE  $category_sql AND $cidade_sql AND $bairro_tudo AND  $preco_between AND $quartos_tudo") or die(mysql_error());
}
elseif($bairro=="Tudo")
{
$data = mysql_query("SELECT  * FROM _Form_Nr_2 WHERE  $category_sql AND $cidade_sql AND $bairro_tudo AND  $preco_between AND $quartos_sql") or die(mysql_error());
}
elseif($quartos=="Tudo")
{
$data = mysql_query("SELECT  * FROM _Form_Nr_2 WHERE  $category_sql AND $cidade_sql AND $bairro_sql AND  $preco_between AND $quartos_tudo") or die(mysql_error());
}
else
$data = mysql_query("SELECT  * FROM _Form_Nr_2 WHERE  $category_sql AND $cidade_sql") or die(mysql_error());

	

		while($row = mysql_fetch_array($data))
		{	
// beginning of row//
echo '<tr style=" border-bottom: 1px solid #fff;" onmouseover="mover(this);" onmouseout="mout(this);">';

... and so on...

thanks
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