Home > Backend Development > PHP Tutorial > PHP高手,我刚刚学PHP,在生成静态分页遇到了点有关问题,就是翻页的有关问题,希望可以給出一个漂亮完整的翻页代码,多谢

PHP高手,我刚刚学PHP,在生成静态分页遇到了点有关问题,就是翻页的有关问题,希望可以給出一个漂亮完整的翻页代码,多谢

WBOY
Release: 2016-06-13 10:14:44
Original
966 people have browsed it

各位大哥PHP高手,小弟我刚刚学PHP,在生成静态分页遇到了点问题,就是翻页的问题,希望可以給出一个漂亮完整的翻页代码,谢谢!




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




$conn=mysql_connect('localhost','root','123456')
  or die('连接失败:'.mysql_error());
//选择数据表
if (mysql_select_db('bbs',$conn))
  {
  echo'选择数据库成功!'.'

';
  
  }
  else
  {
  echo'数据库选择失败!'.mysql_error().'

';
  }
@header("Content-Type: text/html; charset=utf-8");
mysql_query("SET NAMES 'utf8'");
 
$fp = fopen ("moban/temp.html","r");
$content = fread ($fp,filesize ("moban/temp.html"));
$onepage =2;
$sql = "select id from message";
$query = mysql_query ($sql);
$num = mysql_num_rows ($query);
$allpages = ceil ($num / $onepage);
$filedir="news_1";
if (!is_dir($filedir)) {
//如果不存在就建立
mkdir($filedir,0777);
}
for ($i = 0;$iif ($i == 0){
$indexpath = "$filedir/index.html";
} else {
$indexpath = "$filedir/index_".$i.".html";
}
$start = $i * $onepage;
$list = '';
$sql_for_page = "select * from message limit $start,$onepage";
$result=mysql_query($sql_for_page);
 while($row=mysql_fetch_array($result))
 {
 $list .=$row['id']."   ".$row['title'].'
'.$row['content'].'
'; 
 } 
$content1 = str_replace ("{ articletable }",$list.$i,$content);
//分页
$list1 = '';
for ($j = 0;$jif ($j == 0){
$list1 .= '第'.$j.'页 |';
} else {
$list1 .= "第".$j."页 |";
}
}
$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 ("生成分页文件完成,如生成不完全,请检查文件权限系统后重新生成!");
?>



------解决方案--------------------
分页不是有许许多多线程的分页类嘛?都不合适?

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template