01.
<?php
02.
$objConnect
= mysql_connect(
"localhost"
,
"root"
,
"root"
)
or
die
(mysql_error());
03.
$objDB
= mysql_select_db(
"room"
)
or
die
(
"Error Connect to Database"
);
04.
mysql_query(
"SET NAMES UTF8"
);
05.
06.
07.
if
(
$_GET
[
'Action'
] ==
'Update'
){
08.
09.
if
(
$_GET
[
'p_status'
] ==
'0'
){
$status
=
'1'
; }
else
{
$status
=
'0'
; }
10.
11.
$upSQL
=
" UPDATE permits SET p_status = '$status' WHERE p_id = '"
.
$_GET
['p_id
']."'
";
12.
$upQuery
= mysql_query(
$upSQL
);
13.
14.
echo
"<script>window.location='"
.
$_SERVER
['PHP_SELF
']."'
;</script>";
15.
exit
();
16.
17.
}
18.
?>
19.
<html>
20.
<head>
21.
<meta http-equiv=
"Content-Type"
content=
"text/html; charset=UTF-8"
>
22.
<title></title>
23.
</head>
24.
<body>
25.
<form name=
"Search"
method=
"get"
action=
"<?=$_SERVER['PHP_SELF'];?>"
>
26.
<table>
27.
<tr>
28.
<td>กรุณาใส่รหัสสมาชิกหรือชื่อสมาชิก :
29.
<input type=
"text"
name=
"txtSearch"
value=
"<?=$_GET['txtSearch'];?>"
/>
30.
<input type=
"submit"
name=
"btnSubmit"
value=
"ค้นหา"
/>
31.
<input type=
"button"
name=
"btnBorrow"
value=
"แสดงที่ยังไม่คืน"
onClick=
"window.location.href='<?=$_SERVER['PHP_SELF'];?>?Action=Borrow'"
/>
32.
<input type=
"button"
name=
"btnReturn"
value=
"แสดงที่คืนแล้ว"
onClick=
"window.location.href='<?=$_SERVER['PHP_SELF'];?>?Action=Return'"
/>
33.
<input type=
"button"
name=
"btnAll"
value=
"แสดงทั้งหมด"
onClick=
"window.location.href='<?=$_SERVER['PHP_SELF'];?>?Action=All'"
/>
34.
</td>
35.
</tr>
36.
</table>
37.
</form>
38.
39.
<table width=
"100%"
border=
"1"
cellpadding=
"1"
cellspacing=
"0"
>
40.
<tr>
41.
<th width=
"10%"
>ลำดับ</th>
42.
<th width=
"10%"
>รหัสสมาชิก</th>
43.
<th width=
"10%"
>ชื่อสมาชิก</th>
44.
<th width=
"10%"
>รหัสหนังสือ</th>
45.
<th width=
"10%"
>ชื่อหนังสือ</th>
46.
<th width=
"15%"
>วันที่ยืม</th>
47.
<th width=
"15%"
>วันที่คืน</th>
48.
<th width=
"10%"
>สถานะ</th>
49.
<th width=
"10%"
>คืนหนังสือ</th>
50.
</tr>
51.
<?php
52.
$Num
= 0;
53.
$strSQL
=
" SELECT * FROM permits"
;
54.
$strSQL
.=
" LEFT JOIN customers ON permits.c_id = customers.c_id"
;
55.
$strSQL
.=
" LEFT JOIN books ON permits.b_id = books.b_id"
;
56.
57.
if
(isset(
$_GET
[
'btnSubmit'
]) &&
$_GET
[
'txtSearch'
] !=
""
){
58.
59.
$strSQL
.=
" WHERE (customers.c_id LIKE '%"
.
$_GET
['txtSearch
']."%'
) OR (customers.c_name LIKE
'%".$_GET['
txtSearch
']."%'
) ";
60.
61.
}
else
if
(
$_GET
[
'Action'
] ==
'Borrow'
||
empty
(
$_GET
[
'Action'
])){
62.
63.
$strSQL
.=
" WHERE p_status = '0' "
;
64.
65.
}
else
if
(
$_GET
[
'Action'
] ==
'Return'
){
66.
67.
$strSQL
.=
" WHERE p_status = '1' "
;
68.
69.
}
70.
71.
$objQuery
= mysql_query(
$strSQL
);
72.
if
(mysql_num_rows(
$objQuery
) > 0){
73.
while
(
$objResult
= mysql_fetch_array(
$objQuery
)){
74.
$Num
++;
75.
?>
76.
<tr>
77.
<td><?=
$Num
;?></td>
78.
<td><?=
$objResult
[
'c_id'
];?></td>
79.
<td><?=
$objResult
[
'c_name'
];?></td>
80.
<td><?=
$objResult
[
'b_id'
];?></td>
81.
<td><?=
$objResult
[
'b_name'
];?></td>
82.
<td><?=
$objResult
[
'p_borrow'
];?></td>
83.
<td><?=
$objResult
[
'p_return'
];?></td>
84.
<td><?php
if
(
$objResult
[
'p_status'
] ==
'0'
){
echo
'ยังไม่คืน'
; }
else
{
echo
'คืนแล้ว'
; } ?></td>
85.
<td><a href=
"<?=$_SERVER['PHP_SELF'];?>?Action=Update&p_id=<?=$objResult['p_id'];?>&p_status=<?=$objResult['p_status'];?>"
>คืน</a></td>
86.
</tr>
87.
<?php } }
else
{ ?>
88.
<tr align=
"center"
>
89.
<td colspan=
"9"
>ไม่พบข้อมูล</td>
90.
</tr>
91.
<?php } ?>
92.
</table>
93.
</body>
94.
</html>