用PHP生成html分页列表的代码


<?php
$db = mysql_connect("127.0.0.1","root","*******") or die("cant't connect host");
$re = mysql_select_db("t",$db)or die ("can't open database");

$sql = "Select * FROM news";
$res = mysql_query($sql);
$row = mysql_num_rows($res);

$pagesize = 2; //分页
行数
if($row<$pagesize) $pages = 1;
if($row%$pagesize){
$pages = intval($row/$pagesize)+1;
}else{
$pages = intval($row/$pagesize);
}

for($i=1;$i<=$pages;$i++){
$page_turn="";
if($i==1){
$indexpath="index.html";
$page_turn.="First | Front";
}else{
$indexpath="index_".$i.".html";
$page_turn.="<a href='index.html'>First</a> | <a href='index_".($i-1).".html'>Front</a>";
}
if($i==$pages){
$page_turn.=' | Behind | Last';
}else{
$page_turn.=" | <a href='index_".($i+1).".html'>Behind</a> | <a href='index_".$pages.".html'>Last</a>";
}
$search = $sql." LIMIT ".($i-1)*$pagesize .", $pagesize";
$result = mysql_query($search);
$rows = mysql_num_rows($result);
$j=1;
$list="";
while($j<=$rows){
$doc = mysql_fetch_array($result);
$id = $doc['0'];
$title = $doc['1'];
$path = $doc['3'];
$list .="<a href='".$id.".html'>".$title."</a><br>";
$j+=1;
}
$list.="<br><br>".$page_turn;
$fp = fopen("html/list.html","r");
$str = fread($fp,filesize("html/list.html"));
$str = str_replace("{content}",$list,$str);
fclose($fp);

$handle = fopen($path."/".$indexpath,"w");
fwrite($handle,$str);
fclose($handle);
}
copy($path."/index.html",$path."/index_1.html");
?>



相关阅读:
给光标添加CSS样式
恢复忘记的MySQL 5.0数据库的root密码
点击后慢慢弹出下拉菜单效果代码(栏目管理常用)
让FF和IE离得更近
asp.net下OnClientClick的妙用!
Oracle触发器介绍 语句级触发器
.NET 2.0中Hashtable快速查找的方法
在ASP中用EasyMailObject处理Exchange邮件源代码---补充说明
VBS教程:方法-Delete 方法
javascript 写类方式之十
Oracle Spool的用法小结
MySQL 自动备份与数据库被破坏后的恢复方法
在FreeBSD5.1简单安装Postfix+Qpopper+Openwebmail
session和cookie的最深刻理解
快速导航

Copyright © 2016 phpStudy |