function pagech($page,$j){
if($j==1){
$p=$page+1;}
else{
$p=$page-1;}
return $p;
}
$pagecounts=20;
if($startpage){
$startpage=$startpage;
}
else{
$startpage=1;
}
$sqltr="select * from main order by sm limit ".pagetorecord($startpage,$pagecounts).",".$pagecounts;
$connect=MySQL_connect("localhost","http","something");
$select=MySQL_select_db('book',$connect);
$query=MySQL_query('select count(*) as total from main',$connect);
$totalrecord=MySQL_result($query,0,"total");
$query=MySQL_query($sqltr,$connect);
//-------------------------------
echo "<table border=1 cellpadding=0 cellspacing=0>";
echo"<tr><td>序號</td><td>標准書號</td><td>書名</td><td>出版社</td><td>定價</td></tr>";
$i=1;
while($array=MySQL_fetch_array($query)){
printf("<tr><td>%d</td><td>%s</td><td>%s</td><td>%s</td><td>%f</td></tr>",
$i,$array[bzsh],$array[sm],$array[cbs],$array[dj]);
$i++;
}
echo"</table>";
echo"<hr>";
MySQL_close($connect);
if(0==$totalrecord%$pagecounts){
$totalpage=floor($totalrecord/$pagecounts);}
else{
$totalpage=floor($totalrecord/$pagecounts)+1;
}
//echo $sqltr;
if($startpage==1){
if($totalpage>1){
echo"首頁 ";
echo"前頁 ";
echo "<a href=../../".basename($PHP_SELF)."?startpage=".pagech($startpage,1).">下頁 </a>";
echo "<a href=../../".basename($PHP_SELF)."?startpage=".$totalpage.">尾頁</a> 共".$totalpage."頁 第".$startpage."頁";
}
else{
echo"首頁 ";
echo"前頁 ";
echo"下頁 ";
echo"尾頁 ";
}
}
elseif($startpage==$totalpage){
echo "<a href=../../".basename($PHP_SELF)."?startpage=1>首頁 </a>";
echo "<a href=../../".basename($PHP_SELF)."?startpage=".pagech($startpage,-1).">前頁 </a>";
echo"下頁 ";
echo"尾頁 共".$totalpage."頁 第".$startpage."頁";
}
else{
echo "<a href=../../".basename($PHP_SELF)."?startpage=1>首頁 </a>";
echo "<a href=../../".basename($PHP_SELF)."?startpage=".pagech($startpage,-1).">前頁 </a>";
echo "<a href=../../".basename($PHP_SELF)."?startpage=".pagech($startpage,1).">下頁 </a>";
echo "<a href=../../".basename($PHP_SELF)."?startpage=".$totalpage.">尾頁</a> 共".$totalpage."頁 第".$startpage."頁";
}
?>
原作者:不詳
來源:中國PHP自由聯盟