001.
<html>
002.
<head>
003.
<title>ค้นหา</title>
004.
<style type=
"text/css"
>
005.
th {font-family:sans-serif;
006.
font-size:12px;
007.
}
008.
.style1 {color: #990000}
009.
</style>
011.
<script type=
"text/javascript"
>
012.
google.load(
"jquery"
,
"1.3.2"
);
013.
</script>
014.
<script type=
"text/javascript"
>
015.
function
get_search (p, t, x){
016.
var
p = $(
"#price"
).val();
017.
var
t = $(
"#txtKeyword"
).val();
018.
var
x = $(
"#ref_id_type_lease"
).val();
019.
020.
if
(p.length==0 && t.length==0 && x.length==0){
021.
alert(
'โปรดเลือกราคาหรือชื่อหอพักที่ต้องการค้นหา'
);
022.
}
023.
024.
}
025.
</script>
026.
<meta http-equiv=
"Content-Type"
content=
"text/html; charset=windows-874"
></head>
027.
<body>
028.
<center><table width=
"988"
border=
"0"
bgcolor=
"#00FFCC"
>
029.
<tr>
030.
<td align=
"center"
>
031.
<?
032.
@
include
"headder.php"
;
033.
@
include
"menu.php"
;
034.
@
include
"connect.php"
;
035.
?>
036.
037.
<form name=
"frmSearch"
method=
"post"
action=
"<?=$_SERVER['PHP_SELF']?>"
onSubmit=
"get_search (price, txtKeyword, ref_id_type_lease)"
>
038.
<table width=
"1000"
border=
"0"
align=
"center"
cellpadding=
"0"
cellspacing=
"0"
>
039.
<tr>
040.
<th width=
"631"
bgcolor=
"#33CCFF"
><div align=
"center"
>ประเภทการเช่าหอพัก
041.
<select name=
"ref_id_type_lease"
id=
"ref_id_type_lease"
>
042.
<option value=
""
>เลือกประเภทการเช่าหอพัก</option>
043.
<?
044.
$sql
=
"SELECT * FROM tb_type_lease"
;
045.
$result
=mysql_query(
$sql
);
046.
while
(
$rs
=mysql_fetch_array(
$result
)){?>
047.
<option value=
"<?=$rs['id_type_lease']?>"
<?
if
(
$_REQUEST
[
'ref_id_type_lease'
]==
$rs
[
'id_type_lease'
]){?>selected<? }?>><?=
$rs
[
'name_type_lease'
]?></option>
048.
<? }?>
049.
</select>
050.
ราคาห้องพัก
051.
<select name=
"price"
id=
"price"
>
052.
<option value=
""
>- เลือกราคา -</option>
053.
<option value=
"1"
<?
if
(
$price
==1){?>selected<? }?>>น้อยกว่า1000</option>
054.
<option value=
"2"
<?
if
(
$price
==2){?>selected<? }?>>1001-1500</option>
055.
<option value=
"3"
<?
if
(
$price
==3){?>selected<? }?>>1501-2000</option>
056.
<option value=
"4"
<?
if
(
$price
==4){?>selected<? }?>>2001-2500</option>
057.
<option value=
"5"
<?
if
(
$price
==5){?>selected<? }?>>2501-3000</option>
058.
<option value=
"6"
<?
if
(
$price
==6){?>selected<? }?>>มากกว่า 3000</option>
059.
</select>
060.
ชื่อหอพัก
061.
<input name=
"txtKeyword"
style=
"background-color:#99FF99; color:#000000;"
type=
"text"
id=
"txtKeyword"
value=
"<?=$_POST["
txtKeyword
"];?>"
>
062.
<input name=
"submit"
type=
"submit"
style=
"background-color:green; color:yellow;"
value=
"Search"
>
063.
</div></th>
064.
</tr>
065.
</table>
066.
</form>
067.
<?
068.
if
(
$_REQUEST
[
'ref_id_type_lease'
]!=
''
){
069.
$type
=
$_REQUEST
[
'ref_id_type_lease'
];
070.
$where
=
"WHERE id_type_lease = '$type' "
;
071.
}
072.
073.
if
(
$_REQUEST
[
'price'
]!=
''
){
074.
$price
=
$_REQUEST
[
'price'
];
075.
switch
(
$price
){
076.
case
1:
077.
$where
=
" WHERE price_prd < 1000 "
;
078.
break
;
079.
case
2:
080.
$where
=
" WHERE price_prd BETWEEN 1001 AND 1500 "
;
081.
break
;
082.
case
3:
083.
$where
=
" WHERE price_prd BETWEEN 1501 AND 2000 "
;
084.
break
;
085.
case
4:
086.
$where
=
" WHERE price_prd BETWEEN 2001 AND 2500 "
;
087.
break
;
088.
case
5:
089.
$where
=
" WHERE price_prd BETWEEN 2501 AND 3000 "
;
090.
break
;
091.
case
6:
092.
$where
=
" WHERE price_prd > 3000 "
;
093.
break
;
094.
}
095.
}
096.
if
(
$_REQUEST
[
"txtKeyword"
] !=
""
){
097.
098.
$detail
=
$_REQUEST
[
"txtKeyword"
];
099.
$where
=
" WHERE (name_prd LIKE '%"
.
$detail
.
"%') "
;
100.
}
101.
if
(
$_REQUEST
[
'price'
]!=
''
&&
$_REQUEST
[
"txtKeyword"
] !=
""
&&
$_REQUEST
[
'ref_id_type_lease'
]!=
''
){
102.
103.
$type
=
$_REQUEST
[
'ref_id_type_lease'
];
104.
$price
=
$_REQUEST
[
'price'
];
105.
$name_prd
=
$_REQUEST
[
"txtKeyword"
];
106.
switch
(
$price
){
107.
case
1:
108.
$where
=
" WHERE price_prd < 1000 OR name_prd LIKE '%"
.
$name_prd
.
"%' OR id_type_lease = '$type' "
;
109.
break
;
110.
case
2:
111.
$where
=
" WHERE price_prd BETWEEN 1001 AND 1500 OR name_prd LIKE '%"
.
$name_prd
.
"%' OR id_type_lease = '$type' "
;
112.
break
;
113.
case
3:
114.
$where
=
" WHERE price_prd BETWEEN 1501 AND 2000 OR name_prd LIKE '%"
.
$name_prd
.
"%' OR id_type_lease = '$type' "
;
115.
break
;
116.
case
4:
117.
$where
=
" WHERE price_prd BETWEEN 2001 AND 2500 OR name_prd LIKE '%"
.
$name_prd
.
"%' OR id_type_lease = '$type' "
;
118.
break
;
119.
case
5:
120.
$where
=
" WHERE price_prd BETWEEN 2501 AND 3000 OR name_prd LIKE '%"
.
$name_prd
.
"%' OR id_type_lease = '$type' "
;
121.
break
;
122.
case
6:
123.
$where
=
" WHERE price_prd > 3000 OR name_prd LIKE '%"
.
$name_prd
.
"%' OR id_type_lease = '$type' "
;
124.
break
;
125.
}
126.
}
127.
128.
?>
129.
<table width=
"1000"
border=
"0"
align=
"center"
cellpadding=
"0"
cellspacing=
"1"
>
130.
<tr>
131.
<th width=
"92"
align=
"center"
bgcolor=
"#FF9900"
> <div align=
"center"
>รหัสหอพัก</div></th>
132.
<th width=
"97"
align=
"center"
bgcolor=
"#FF9900"
> <div align=
"center"
>ชื่อหอพัก </div></th>
133.
<th width=
"140"
align=
"center"
bgcolor=
"#FF9900"
> <div align=
"center"
>ประเภทหอพัก </div></th>
134.
<th width=
"83"
align=
"center"
bgcolor=
"#FF9900"
> <div align=
"center"
>ราคา</div></th>
135.
<th width=
"110"
align=
"center"
bgcolor=
"#FF9900"
> <div align=
"center"
>รูปภาพ </div></th>
136.
<th width=
"170"
align=
"center"
bgcolor=
"#FF9900"
> <div align=
"center"
>รายละเอียด</div></th>
137.
</tr>
138.
<?
139.
if
(
$price
!=
''
||
$txtKeyword
!=
''
||
$type
!=
''
){
140.
$strSQL
=
" SELECT * FROM tb_product "
;
141.
$strSQL
.=
" LEFT JOIN tb_type ON tb_product .ref_id_type = tb_type.id_type"
;
142.
$strSQL
.=
" LEFT JOIN tb_type_lease ON tb_product .ref_id_type_lease = tb_type_lease.id_type_lease"
;
143.
$strSQL
.=
" $where"
;
144.
$objQuery
= mysql_query(
$strSQL
);
145.
$Num_Rows
= mysql_num_rows(
$objQuery
);
146.
147.
$Per_Page
=10;
148.
149.
$Page
=
$_GET
[
"Page"
];
150.
if
(!
$_GET
[
"Page"
])
151.
{
152.
$Page
=1;
153.
}
154.
155.
$Prev_Page
=
$Page
-1;
156.
$Next_Page
=
$Page
+1;
157.
158.
$Page_Start
= ((
$Per_Page
*
$Page
)-
$Per_Page
);
159.
if
(
$Num_Rows
<=
$Per_Page
)
160.
{
161.
$Num_Pages
=1;
162.
}
163.
else
if
((
$Num_Rows
%
$Per_Page
)==0)
164.
{
165.
$Num_Pages
=(
$Num_Rows
/
$Per_Page
) ;
166.
}
167.
else
168.
{
169.
$Num_Pages
=(
$Num_Rows
/
$Per_Page
)+1;
170.
$Num_Pages
= (int)
$Num_Pages
;
171.
}
172.
173.
$strSQL
.=
" order by id_prd ASC LIMIT $Page_Start , $Per_Page"
;
174.
$objQuery
= mysql_query(
$strSQL
);
175.
176.
$bg
= 1;
177.
while
(
$objResult
= mysql_fetch_array(
$objQuery
)) {
$bg
++;
178.
if
(
$bg
%2==0){
179.
$bgr
=
'#99FF99'
;
180.
}
else
{
181.
$bgr
=
'#00FFCC'
;
182.
}
183.
?>
184.
<tr bgcolor=
"<?=$bgr?>"
>
185.
<td height=
"50"
><div align=
"center"
>
186.
<?=
$objResult
[
"id_prd"
];?>
187.
</div></td>
188.
<td><div align=
"center"
>
189.
<?=
$objResult
[
"name_prd"
];?>
190.
</div></td>
191.
<td><div align=
"center"
>
192.
<?=
$objResult
[
"name_type"
];?>
193.
</div></td>
194.
<td><div align=
"center"
>
195.
<?=
$objResult
[
"price_prd"
];?>
196.
</div></td>
197.
<td align=
"right"
><div align=
"center"
><img src=
'photo/<?=$objResult["photo_prd"];?>'
width=
'80'
height=
'60'
/></div></td>
198.
<td><div align=
"center"
>[ <A HREF=
'search_view.php?id_prd=<?=$objResult["id_prd"];?>'
>แสดงรายละเอียด </A>] </div>
199.
</div></td>
200.
</tr>
201.
<? }}?>
202.
</table>
203.
<div align=
"center"
><br>
204.
<div align=
"center"
>
205.
<center>
206.
</center>
207.
</div>
208.
<span
class
=
"style1"
>จำนวนหอพักทั้งหมด</span>
209.
<?=
$Num_Rows
;?>
210.
<span
class
=
"style1"
>หอพัก:หน้า :</span>
211.
<?
212.
if
(
$Prev_Page
)
213.
{
214.
echo
" <a href='$_SERVER[SCRIPT_NAME]?Page=$Prev_Page&price=$_REQUEST[price]&txtKeyword=$_REQUEST[txtKeyword]'><< Back</a> "
;
215.
}
216.
217.
for
(
$i
=1;
$i
<=
$Num_Pages
;
$i
++){
218.
if
(
$i
!=
$Page
)
219.
{
220.
echo
"[ <a href='$_SERVER[SCRIPT_NAME]?Page=$i&price=$_REQUEST[price]&txtKeyword=$_REQUEST[txtKeyword]'>$i</a> ]"
;
221.
}
222.
else
223.
{
224.
echo
"<b> $i </b>"
;
225.
}
226.
}
227.
if
(
$Page
!=
$Num_Pages
)
228.
{
229.
echo
" <a href ='$_SERVER[SCRIPT_NAME]?Page=$Next_Page&price=$_REQUEST[price]&txtKeyword=$_REQUEST[txtKeyword]'>Next>></a> "
;
230.
}
231.
232.
?>
233.
</div>
234.
<p>
235.
<?
include
"fooder.php"
?>
236.
</p></td>
237.
</tr>
238.
</table></center>
239.
<p> </p>
240.
</body>
241.
</html>