<?
$province_id2 = $_POST['provinceHidden'];
$amphur_id2 = $_POST['amphurHidden'];
$district_id2 = $_POST['tumbonHidden'];
$pmin = str_replace(',', '', $_POST['Pmin']);
$pmax = str_replace(',', '', $_POST['Pmax']);
$style = $_POST['group1'];
$pagad = $_POST['group2'];
$province_id = rtrim($province_id2);
$amphur_id = rtrim($amphur_id2);
$district_id = rtrim($district_id2);
?>
<div class ="row">
<?php
include "include/Conn.php";
mysql_query('SET NAMES UTF8'); // set กำหนดมาตราฐาน
if(!empty($province_id) && empty($amphur_id) && empty($district_id) && empty($pmin) && empty($pmax) && !empty($style) && !empty($pagad)){
$sql = "SELECT * FROM topic WHERE province LIKE '%".$province_id."%'";
}
else if(!empty($province_id) && !empty($amphur_id) && empty($district_id) && empty($pmin) && empty($pmax) && !empty($style) && !empty($pagad)){
$sql = "SELECT * FROM topic WHERE province LIKE '%".$province_id."%' AND zone LIKE '%".$amphur_id."%'";
}
else if(!empty($province_id) && !empty($amphur_id) && !empty($district_id) && empty($pmin) && empty($pmax) && !empty($style) && !empty($pagad)){
$sql = "SELECT * FROM topic WHERE province LIKE '%".$province_id."%'AND zone LIKE '%".$amphur_id."%' AND tumbon LIKE '%".$district_id."%'";
}
else if(!empty($province_id) && !empty($amphur_id) && !empty($district_id) && !empty($pmin) && !empty($pmax) && !empty($style) && !empty($pagad)){
$sql = "SELECT * FROM topic WHERE province LIKE '%".$province_id."%'AND zone LIKE '%".$amphur_id."%' AND tumbon LIKE '%".$district_id."%' AND price between '".$pmin."' AND '".$pmax."' ";
}
else if(!empty($province_id) && !empty($amphur_id) && !empty($district_id) && !empty($pmin) && !empty($pmax) && !empty($style) && !empty($pagad)){
$sql = "SELECT * FROM topic WHERE province LIKE '%".$province_id."%'AND zone LIKE '%".$amphur_id."%' AND tumbon LIKE '%".$district_id."%' AND price between '".$pmin."' AND '".$pmax."' AND style = '".$style."'";
}
else if(!empty($province_id) && !empty($amphur_id) && !empty($district_id) && !empty($pmin) && !empty($pmax) && !empty($style) && !empty($pagad)){
$sql = "SELECT * FROM topic WHERE province LIKE '%".$province_id."%'AND zone LIKE '%".$amphur_id."%' AND tumbon LIKE '%".$district_id."%' AND price between '".$pmin."' AND '".$pmax."' AND style = '".$style."' AND pagad like '".$pagad."'";
}
else if(empty($province_id) && empty($amphur_id) && empty($district_id) && !empty($pmin) && !empty($pmax) && !empty($style) && !empty($pagad)){
$sql = "SELECT * FROM topic WHERE price between '".$pmin."' AND '".$pmax."' ";
}
else if(empty($province_id) && empty($amphur_id) && empty($district_id) && empty($pmin) && empty($pmax) && !empty($style) && !empty($pagad)){
$sql = "SELECT * FROM topic WHERE style = '".$style."' ";
}
else if(empty($province_id) && empty($amphur_id) && empty($district_id) && empty($pmin) && empty($pmax) && !empty($style) && !empty($pagad)){
$sql = "SELECT * FROM topic WHERE pagad like '".$pagad."'";
}
else if(empty($province_id) && empty($amphur_id) && empty($district_id) && !empty($pmin) && !empty($pmax) && !empty($style) && !empty($pagad)){
$sql = "SELECT * FROM topic WHERE price between '".$pmin."' AND '".$pmax."' AND style like '".$style."'";
}
else if(empty($province_id) && empty($amphur_id) && empty($district_id) && !empty($pmin) && !empty($pmax) && !empty($style) && !empty($pagad)){
$sql = "SELECT * FROM topic WHERE price between '".$pmin."' AND '".$pmax."' AND style like '".$style."' AND pagad like '".$pagad."'";
}
else if(empty($province_id) && empty($amphur_id) && empty($district_id) && !empty($pmin) && !empty($pmax) && !empty($style) && !empty($pagad)){
$sql = "SELECT * FROM topic WHERE price between '".$pmin."' AND '".$pmax."' AND pagad like '".$pagad."'";
}
else if(empty($province_id) && empty($amphur_id) && empty($district_id) && empty($pmin) && empty($pmax) && !empty($style) && !empty($pagad)){
$sql = "SELECT * FROM topic WHERE style like '".$style."' AND pagad like '".$pagad."'";
}
else if(!empty($province_id) && empty($amphur_id) && empty($district_id) && !empty($pmin) && !empty($pmax) && !empty($style) && !empty($pagad)){
$sql = "SELECT * FROM topic WHERE province LIKE '%".$province_id."%' AND price between '".$pmin."' AND '".$pmax."' ";
}
else if(!empty($province_id) && !empty($amphur_id) && empty($district_id) && !empty($pmin) && !empty($pmax) && !empty($style) && !empty($pagad)){
$sql = "SELECT * FROM topic WHERE province LIKE '%".$province_id."%' AND zone LIKE '%".$amphur_id."%' AND price between '".$pmin."' AND '".$pmax."' ";
}
else if(!empty($province_id) && empty($amphur_id) && empty($district_id) && empty($pmin) && empty($pmax) && !empty($style) && !empty($pagad)){
$sql = "SELECT * FROM topic WHERE province LIKE '%".$province_id."%' AND style like '".$style."'";
}
else if(!empty($province_id) && empty($amphur_id) && empty($district_id) && empty($pmin) && empty($pmax) && !empty($style) && !empty($pagad)){
$sql = "SELECT * FROM topic WHERE province LIKE '%".$province_id."%' AND style like '".$style."' AND pagad like '".$pagad."'";
}
else if(!empty($province_id) && empty($amphur_id) && empty($district_id) && empty($pmin) && empty($pmax) && empty($style) && !empty($pagad)){
$sql = "SELECT * FROM topic WHERE province LIKE '%".$province_id."%' AND pagad like '".$pagad."'";
}
else if(!empty($province_id) && !empty($amphur_id) && empty($district_id) && empty($pmin) && empty($pmax) && !empty($style) && !empty($pagad)){
$sql = "SELECT * FROM topic WHERE province LIKE '%".$province_id."%' AND zone LIKE '%".$amphur_id."%' AND style like '".$style."' ";
}
else if(!empty($province_id) && !empty($amphur_id) && !empty($district_id) && empty($pmin) && empty($pmax) && !empty($style) && !empty($pagad)){
$sql = "SELECT * FROM topic WHERE province LIKE '%".$province_id."%' AND zone LIKE '%".$amphur_id."%' AND tumbon LIKE '%".$district_id."%' AND style like '".$style."' ";
}
else if(!empty($province_id) && !empty($amphur_id) && empty($district_id) && empty($pmin) && empty($pmax) && !empty($style) && !empty($pagad)){
$sql = "SELECT * FROM topic WHERE province LIKE '%".$province_id."%' AND zone LIKE '%".$amphur_id."%' AND pagad like '".$pagad."'";
}
else if(!empty($province_id) && !empty($amphur_id) && !empty($district_id) && empty($pmin) && empty($pmax) && !empty($style) && !empty($pagad)){
$sql = "SELECT * FROM topic WHERE province LIKE '%".$province_id."%' AND zone LIKE '%".$amphur_id."%' AND tumbon LIKE '%".$district_id."%' AND pagad like '".$pagad."'";
}
else if(!empty($province_id) && !empty($amphur_id) && !empty($district_id) && empty($pmin) && empty($pmax) && !empty($style) && !empty($pagad)){
$sql = "SELECT * FROM topic WHERE province LIKE '%".$province_id."%' AND zone LIKE '%".$amphur_id."%' AND tumbon LIKE '%".$district_id."%' AND style like '".$style."' AND pagad like '".$pagad."'";
}
else if(!empty($province_id) && empty($amphur_id) && empty($district_id) && empty($pmin) && !empty($pmax) && !empty($style) && !empty($pagad)){
$sql = "SELECT * FROM topic WHERE province LIKE '%".$province_id."%' AND price between '1' AND '".$pmax."' AND style like '".$style."' AND pagad like '".$pagad."'";
}
else if(!empty($province_id) && empty($amphur_id) && empty($district_id) && !empty($pmin) && empty($pmax) && !empty($style) && !empty($pagad)){
$sql = "SELECT * FROM topic WHERE province LIKE '%".$province_id."%' AND price between '".$pmin."' AND '9999999999999' AND style like '".$style."' AND pagad like '".$pagad."'";
}
else {
echo "ไม่พบข้อมูลที่ต้องการค่ะ";
}
$success =mysql_query($sql);
if($success){
while($row = mysql_fetch_array($success)) {?>
<div class="col-md-3" style="margin-left:20px;margin-top:10px;background-color:white;height:320px;">
<a href="detail.php?id=<?=$row[id]?>"><img src="item/<?=$row[image]?>"width='250' height='150' border='0'>
<br>
<a href="detail.php?id=<?=$row[id]?>"><strong><?=$row[topic]?></strong>
<strong><?=$row[topic]?></strong></a>
<br>
<span class="glyphicon glyphicon-map-marker"></span><?=$row[province]?>
<?=$row[zone]?>
<?=$row[tumbon]?>
<br>ราคา : <font color="#FA0421"><?echo number_format( $row[price] )?> </font>บาท </div>
<?php }
}else if(empty($success)){
echo "ไม่มีข้อมูลนี้".$success."ค่ะ";
}
?>