找回密码
 注册
搜索
热搜: 回贴
  • 前程无忧官网首页 有什么好的平台可以
  • 最新的销售平台 互联网营销的平台有哪
  • 制作网页的基本流程 网页制作和网页设
  • 【帝国CMS】输出带序号的列表(数字排
  • 网站建设公司 三一,中联,极东泵车的
  • 织梦 建站 织梦网站模版后台怎么更改
  • 云服务官网 哪些网站有免费的简历模板
  • 如何建网站要什么条件 建网站要用什么
  • 吉林市移动公司电话 吉林省退休人员网
  • 设计类毕业论文 网站设计与实现毕业论
查看: 9642|回复: 1

php生成静态html分页实现方法

[复制链接]
发表于 2009-11-29 02:41:13 | 显示全部楼层 |阅读模式 IP:江苏扬州
<?php
$conn=mysql_connect('localhost','root','wy')
or die('连接失败:'.mysql_error());


//选择数据表
if (mysql_select_db('mynews',$conn))
{
echo'选择数据库成功!'.'<p>';

}
else
{
echo'数据库选择失败!'.mysql_error().'<p>';
}
@header("Content-Type: text/html; charset=utf-8");
mysql_query("SET NAMES 'utf8'");

$fp = fopen ("temp.html","r");
$content = fread ($fp,filesize ("temp.html"));
$onepage =2;
$sql = "select id from news";
$query = mysql_query ($sql);
$num = mysql_num_rows ($query);
$allpages = ceil ($num / $onepage);
for ($i = 0;$i<$allpages; $i++){
if ($i == 0){
$indexpath = "index.html";
} else {
$indexpath = "index_".$i.".html";
}
$start = $i * $onepage;
$list = '';
$sql_for_page = "select * from news limit $start,$onepage";
$result=mysql_query($sql_for_page);
while($row=mysql_fetch_array($result))
{
        $list .= 'uid='.$row['id'].$row['title'].'<br>';
     }
$content1 = str_replace ("{ articletable }",$list.$i,$content);
//分页
$list1 = '';
for ($j = 0;$j<$allpages; $j++){
if ($j == 0){
$list1 .= '<a href="index.html" >第'.$j.'页 </a>|';
} else {
$list1 .= "<a href='index_".$j.".html' >第".$j."页 </a>|";
}
}
$content2 = str_replace ("{ mune }",$list1,$content1);

if (is_file ($indexpath)){
@unlink ($indexpath); //若文件已存在,则删除
}
$handle = fopen ($indexpath,"w"); //打开文件指针,创建文件
/*
  检查文件是否被创建且可写
*/
if (!is_writable ($indexpath)){
echo "文件:".$indexpath."不可写,请检查其属性后重试!"; //修改为echo
}
if (!fwrite ($handle,$content2)){ //将信息写入文件
echo "生成文件".$indexpath."失败!"; //修改为echo
}
fclose ($handle); //关闭指针
}
fclose ($fp);
die ("生成分页文件完成,如生成不完全,请检查文件权限系统后重新生成!");
?>
temp.html
<HTML>
<TITLE>{ title }</TITLE>
<BODY>
this is a { file } file's templets
{ articletable }
分页         { mune }
</BODY>
</HTML>
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|小黑屋|最新主题|手机版|微赢网络技术论坛 ( 苏ICP备08020429号 )

GMT+8, 2024-9-30 09:23 , Processed in 0.214600 second(s), 12 queries , Gzip On, MemCache On.

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表