01.
<?php
02.
$hostName
=
"localhost"
;
03.
$userName
=
"user"
;
04.
$passWord
=
"user"
;
05.
$conn
= mysql_connect(
$hostName
,
$userName
,
$passWord
)
or
die
(
"ไม่สามารถติดต่อ Server ได้"
);
06.
mysql_query(
"SET NAMES utf8"
,
$conn
);
07.
mysql_query(
"USE db_testcmp"
);
08.
09.
if
(isset(
$_GET
[
'page'
])){
10.
$current_page
=
$_GET
[
'page'
];
11.
}
12.
else
{
13.
$current_page
= 1;
14.
}
15.
$page_size
= 1;
16.
$start_row
= (
$current_page
- 1) *
$page_size
;
17.
?>
18.
<html>
19.
<head>
20.
<meta http-equiv=
"Content-Type"
content=
"text/html; charset=utf-8"
/>
21.
<title>:: ADD Data Computer ::</title>
22.
</head>
23.
<body>
24.
<form action=
"AddCmpSAVE.php"
method=
"POST"
enctype=
"multipart/form-data"
name=
"formCMP"
id=
"formCMP"
>
25.
<?php
26.
$sqlA
=
"SELECT * FROM tb_datacmp ORDER BY cmpID ASC LIMIT $start_row, $page_size"
;
27.
$resultA
= mysql_query(
$sqlA
)
or
die
(
"$sql_Error"
);
28.
while
(
$rowA
= mysql_fetch_array(
$resultA
)){
29.
?>
30.
<p>Computer ID : <input name=
"cmpID"
type=
"text"
id=
"textSN"
value=
"<?=($rowA["
cmpID
"])?>"
size=
"2"
readonly />
31.
<p>Computer Name : <input name=
"textCmpName"
type=
"text"
id=
"textCmpName"
value=
"<?=($rowA['cmpName'])?>"
/>
32.
<p>Serial No. : <input name=
"textSN"
type=
"text"
id=
"textSN"
value=
"<?=($rowA['SN'])?>"
/>
33.
<p>Mac Address : <input name=
"textMAC"
type=
"text"
id=
"textMAC"
value=
"<?=($rowA['MacAddress'])?>"
/>
34.
<?php } ?>
35.
<hr align=
"left"
width=
"300"
size=
"2"
color=
"#FF0000"
>
36.
<input name=
"UpdateData"
type=
"submit"
id=
"UpdateData "
value=
"UpdateData"
>
37.
38.
<!------ แสดงผลจำนวนเรคคอร์ดของข้อมูล จำนวนหน้าและลิงค์หน้าต่อ ๆไป ------>
39.
<?
40.
41.
$result
= mysql_query(
"SELECT COUNT(*) FROM tb_datacmp"
);
42.
43.
$num_rows
= mysql_result(
$result
,0,0);
44.
45.
46.
$num_pages
=
ceil
(
$num_rows
/
$page_size
);
47.
$group_size
= 1;
48.
$current_group
=
ceil
(
$current_page
/
$group_size
);
49.
50.
echo
"total <b>$num_rows</b> page "
;
51.
echo
"| <b>$current_page</b>/<b>$num_pages</b>"
;
52.
echo
"        "
;
53.
54.
if
(
$current_group
> 1){
55.
56.
$last_page_of_last_group
= (
$current_group
- 1) *
$group_size
;
57.
echo
"<a href=$PHP_SELF?page=1><b>«</b>"
;
58.
echo
"<a href=\""
.
$_SERVER
[
'PHP_SELF'
] .
"?"
;
59.
echo
"page=$last_page_of_last_group\" > <b>‹</b></a> "
;
60.
}
61.
62.
$first_page_of_current_group
= ((
$current_group
- 1) *
$group_size
) + 1;
63.
$last_page_of_current_group
=
$current_group
*
$group_size
;
64.
65.
if
(
$last_page_of_current_group
<=
$num_pages
){
66.
$end
=
$last_page_of_current_group
;
67.
}
68.
else
{
69.
$end
=
$num_pages
;
70.
}
71.
for
(
$i
=
$first_page_of_current_group
;
$i
<=
$end
;
$i
++){
72.
73.
if
(
$i
==
$current_page
){
74.
echo
" <font color='red'>"
.
$i
.
"</font> "
;
75.
}
76.
else
{
77.
echo
"<a href=\""
.
$_SERVER
[
'PHP_SELF'
] .
"?"
;
78.
echo
"page=$i\">"
.
$i
.
"</a> "
;
79.
}
80.
}
81.
if
(
$num_pages
>
$last_page_of_current_group
){
82.
83.
84.
$first_page_of_next_group
=
$last_page_of_current_group
+ 1;
85.
echo
"<a href=\""
.
$_SERVER
[
'PHP_SELF'
].
"?"
;
86.
echo
"page=$first_page_of_next_group\"> <b>›</b> </a> "
;
87.
echo
"<a href=$PHP_SELF?page="
.
$num_pages
.
"><b>»</b></a> \n"
;
88.
}
89.
?>
90.
</form>
91.
</body>
92.
</html>