01.
<html>
02.
<head>
03.
<title>ThaiCreate.Com Tutorial</title>
04.
</head>
05.
<body>
06.
<?
07.
$objConnect
= mysql_connect(
"localhost"
,
"root"
,
"root"
)
or
die
(mysql_error());
08.
$objDB
= mysql_select_db(
"mydatabase"
);
09.
$strSQL
=
"SELECT * FROM gallery"
;
10.
$objQuery
= mysql_query(
$strSQL
);
11.
$Num_Rows
= mysql_num_rows(
$objQuery
);
12.
13.
$Per_Page
= 4;
14.
15.
$Page
=
$_GET
[
"Page"
];
16.
if
(!
$_GET
[
"Page"
])
17.
{
18.
$Page
=1;
19.
}
20.
21.
$Prev_Page
=
$Page
-1;
22.
$Next_Page
=
$Page
+1;
23.
24.
$Page_Start
= ((
$Per_Page
*
$Page
)-
$Per_Page
);
25.
if
(
$Num_Rows
<=
$Per_Page
)
26.
{
27.
$Num_Pages
=1;
28.
}
29.
else
if
((
$Num_Rows
%
$Per_Page
)==0)
30.
{
31.
$Num_Pages
=(
$Num_Rows
/
$Per_Page
) ;
32.
}
33.
else
34.
{
35.
$Num_Pages
=(
$Num_Rows
/
$Per_Page
)+1;
36.
$Num_Pages
= (int)
$Num_Pages
;
37.
}
38.
39.
$strSQL
.=
" order by GalleryID ASC LIMIT $Page_Start , $Per_Page"
;
40.
$objQuery
= mysql_query(
$strSQL
);
41.
42.
43.
echo
"<table border=\"0\" cellspacing=\"1\" cellpadding=\"1\"><tr>"
;
44.
$intRows
= 0;
45.
while
(
$objResult
= mysql_fetch_array(
$objQuery
))
46.
{
47.
echo
"<td>"
;
48.
$intRows
++;
49.
?>
50.
<center>
51.
<img src=
"shotdev/<?=$objResult["
Picture
"];?>"
><br>
52.
<?=
$objResult
[
"GalleryName"
];?>
53.
<br>
54.
</center>
55.
<?
56.
echo
"</td>"
;
57.
if
((
$intRows
)%2==0)
58.
{
59.
echo
"</tr>"
;
60.
}
61.
}
62.
echo
"</tr></table>"
;
63.
?>
64.
65.
<br>
66.
Total <?=
$Num_Rows
;?> Record : <?=
$Num_Pages
;?> Page :
67.
<?
68.
if
(
$Prev_Page
)
69.
{
70.
echo
" <a href='$_SERVER[SCRIPT_NAME]?Page=$Prev_Page'><< Back</a> "
;
71.
}
72.
73.
for
(
$i
=1;
$i
<=
$Num_Pages
;
$i
++){
74.
if
(
$i
!=
$Page
)
75.
{
76.
echo
"[ <a href='$_SERVER[SCRIPT_NAME]?Page=$i'>$i</a> ]"
;
77.
}
78.
else
79.
{
80.
echo
"<b> $i </b>"
;
81.
}
82.
}
83.
if
(
$Page
!=
$Num_Pages
)
84.
{
85.
echo
" <a href ='$_SERVER[SCRIPT_NAME]?Page=$Next_Page'>Next>></a> "
;
86.
}
87.
?>
88.
89.
90.
</body>
91.
</html>
92.
<?
93.
mysql_close(
$objConnect
);
94.
?>