001.
<!DOCTYPE html>
002.
<html>
003.
<head>
004.
<meta http-equiv=”Content-Type” content=”text/html; charset=UTF-8″>
005.
<link rel=
"stylesheet"
href=
"css/style.css"
>
006.
007.
</style>
008.
</head>
009.
<body>
010.
011.
<?php
012.
013.
$q
=
intval
(
$_GET
[
'q'
]);
014.
$serverName
=
"localhost"
;
015.
$userName
=
"root"
;
016.
$userPassword
=
"abcd1234"
;
017.
$dbName
=
"thaimee"
;
018.
019.
$con
= mysqli_connect(
$serverName
,
$userName
,
$userPassword
,
$dbName
);
020.
mysqli_set_charset(
$con
,
"utf8"
);
021.
022.
023.
if
(!
$con
) {
024.
die
(
'Could not connect: '
. mysqli_error(
$con
));
025.
}
026.
027.
mysqli_select_db(
$con
,
"thaimee"
);
028.
029.
030.
$sql
=
"SELECT * FROM product order by Productname ASC "
;
031.
if
(
$q
!=0)
$sql
=
"SELECT * FROM product WHERE CategoryID = '"
.
$q
.
"'"
;
032.
033.
034.
035.
$result
= mysqli_query(
$con
,
$sql
);
036.
$num_rows
= mysqli_num_rows(
$result
);
037.
$per_page
= 50;
038.
$page
= 1;
039.
if
(isset(
$_GET
[
"Page"
]))
040.
{
041.
$page
=
$_GET
[
"Page"
];
042.
}
043.
044.
$prev_page
=
$page
-1;
045.
$next_page
=
$page
+1;
046.
047.
$row_start
= ((
$per_page
*
$page
)-
$per_page
);
048.
if
(
$num_rows
<=
$per_page
)
049.
{
050.
$num_pages
=1;
051.
}
052.
else
if
((
$num_rows
%
$per_page
)==0)
053.
{
054.
$num_pages
=(
$num_rows
/
$per_page
) ;
055.
}
056.
else
057.
{
058.
$num_pages
=(
$num_rows
/
$per_page
)+1;
059.
$num_pages
= (int)
$num_pages
;
060.
}
061.
$row_end
=
$per_page
*
$page
;
062.
if
(
$row_end
>
$num_rows
)
063.
{
064.
$row_end
=
$num_rows
;
065.
}
066.
067.
$sql
=
" ORDER BY Productname ASC LIMIT $row_start ,$row_end "
;
068.
$query
= mysqli_query(
$con
,
$sql
);
069.
070.
071.
echo
"<table
class
=
'Thaimeetable'
>
072.
073.
<tr>
074.
<td>No.</td>
075.
<td>Name</td>
076.
<td>Description</td>
077.
<td>Product (TH)</td>
078.
079.
<td>ShelfLife</td>
080.
081.
<td>Packing&Flavor</td>
082.
</tr>";
083.
$i
= 1;
084.
while
(
$row
= mysqli_fetch_array(
$result
)) {
085.
echo
"<tr>"
;
086.
echo
"<td>"
.
$i
.
"</td>"
;
087.
088.
echo
"<td>"
.
$row
[
'Productname'
] .
"</td>"
;
089.
echo
"<td>"
.
$row
[
'Product_description'
] .
"</td>"
;
090.
echo
"<td>"
.
$row
[
'Product_thainame'
] .
"</td>"
;
091.
092.
echo
"<td>"
.
$row
[
'ShelfLife'
] .
"</td>"
;
093.
094.
echo
"</td><td>"
;
095.
echo
"<a href='product_packing_flavor.php?FilesID="
.
$row
['ProductID
']."'
target=
'_blank'
>Packing&Flavor</a>";
096.
echo
"</td>"
;
097.
echo
"</tr>"
;
098.
099.
$i
++;
100.
}
101.
echo
"</table>"
;
102.
?>
103.
<br>
104.
Total <?php
echo
$num_rows
;?> Record : <?php
echo
$num_pages
;?> Page :
105.
<?php
106.
if
(
$prev_page
)
107.
{
108.
echo
" <a href='$_SERVER[SCRIPT_NAME]?Page=$prev_page'><< Back</a> "
;
109.
}
110.
111.
for
(
$i
=1;
$i
<=
$num_pages
;
$i
++){
112.
if
(
$i
!=
$page
)
113.
{
114.
echo
"[ <a href='$_SERVER[SCRIPT_NAME]?Page'>$i</a> ]"
;
115.
}
116.
else
117.
{
118.
echo
"<b> $i </b>"
;
119.
}
120.
}
121.
if
(
$page
!=
$num_pages
)
122.
{
123.
echo
" <a href ='$_SERVER[SCRIPT_NAME]?Page=$next_page'>Next>></a> "
;
124.
}
125.
126.
127.
128.
129.
mysqli_close(
$con
);
130.
131.
?>
132.
133.
</body>
134.
</html>