001.
<html>
002.
<head>
003.
<title>ThaiCreate.Com PHP & MySQL Tutorial</title>
004.
</head>
005.
<body>
006.
<?php
007.
$objConnect
= mysql_connect(
"localhost"
,
"root"
,
"root"
)
or
die
(
"Error Connect to Database"
);
008.
$objDB
= mysql_select_db(
"mydatabase"
);
009.
$strSQL
=
"SELECT * FROM customer "
;
010.
$objQuery
= mysql_query(
$strSQL
)
or
die
(
"Error Query ["
.
$strSQL
.
"]"
);
011.
$Num_Rows
= mysql_num_rows(
$objQuery
);
012.
013.
$Per_Page
= 2;
014.
015.
$Page
=
$_GET
[
"Page"
];
016.
if
(!
$_GET
[
"Page"
])
017.
{
018.
$Page
=1;
019.
}
020.
021.
$Prev_Page
=
$Page
-1;
022.
$Next_Page
=
$Page
+1;
023.
024.
$Page_Start
= ((
$Per_Page
*
$Page
)-
$Per_Page
);
025.
if
(
$Num_Rows
<=
$Per_Page
)
026.
{
027.
$Num_Pages
=1;
028.
}
029.
else
if
((
$Num_Rows
%
$Per_Page
)==0)
030.
{
031.
$Num_Pages
=(
$Num_Rows
/
$Per_Page
) ;
032.
}
033.
else
034.
{
035.
$Num_Pages
=(
$Num_Rows
/
$Per_Page
)+1;
036.
$Num_Pages
= (int)
$Num_Pages
;
037.
}
038.
039.
$strSQL
.=
" order by CustomerID ASC LIMIT $Page_Start , $Per_Page"
;
040.
$objQuery
= mysql_query(
$strSQL
);
041.
?>
042.
<table width=
"600"
border=
"1"
>
043.
<tr>
044.
<th width=
"20"
> <div align=
"center"
>No </div></th>
045.
<th width=
"91"
> <div align=
"center"
>CustomerID </div></th>
046.
<th width=
"98"
> <div align=
"center"
>Name </div></th>
047.
<th width=
"198"
> <div align=
"center"
>Email </div></th>
048.
<th width=
"97"
> <div align=
"center"
>CountryCode </div></th>
049.
<th width=
"59"
> <div align=
"center"
>Budget </div></th>
050.
<th width=
"71"
> <div align=
"center"
>Used </div></th>
051.
</tr>
052.
<?php
053.
$i
= 1;
054.
if
(
$Page
> 1)
055.
{
056.
$i
= (
$Per_Page
* (
$Page
-1)) + 1;
057.
}
058.
while
(
$objResult
= mysql_fetch_array(
$objQuery
))
059.
{
060.
?>
061.
<tr>
062.
<td><div align=
"center"
><?php
echo
$i
;?></div></td>
063.
<td><div align=
"center"
><?php
echo
$objResult
[
"CustomerID"
];?></div></td>
064.
<td><?php
echo
$objResult
[
"Name"
];?></td>
065.
<td><?php
echo
$objResult
[
"Email"
];?></td>
066.
<td><div align=
"center"
><?php
echo
$objResult
[
"CountryCode"
];?></div></td>
067.
<td align=
"right"
><?php
echo
$objResult
[
"Budget"
];?></td>
068.
<td align=
"right"
><?php
echo
$objResult
[
"Used"
];?></td>
069.
</tr>
070.
<?php
071.
$i
++;
072.
}
073.
?>
074.
</table>
075.
076.
<br>
077.
Total <?php
echo
$Num_Rows
;?> Record : <?php
echo
$Num_Pages
;?> Page :
078.
<?php
079.
if
(
$Prev_Page
)
080.
{
081.
echo
" <a href='$_SERVER[SCRIPT_NAME]?Page=$Prev_Page'><< Back</a> "
;
082.
}
083.
084.
for
(
$i
=1;
$i
<=
$Num_Pages
;
$i
++){
085.
if
(
$i
!=
$Page
)
086.
{
087.
echo
"[ <a href='$_SERVER[SCRIPT_NAME]?Page=$i'>$i</a> ]"
;
088.
}
089.
else
090.
{
091.
echo
"<b> $i </b>"
;
092.
}
093.
}
094.
if
(
$Page
!=
$Num_Pages
)
095.
{
096.
echo
" <a href ='$_SERVER[SCRIPT_NAME]?Page=$Next_Page'>Next>></a> "
;
097.
}
098.
mysql_close(
$objConnect
);
099.
?>
100.
</body>
101.
</html>