现在的位置: 首页 > 综合 > 正文

php生成html分页方法-----ob篇

2013年01月08日 ⁄ 综合 ⁄ 共 11094字 ⁄ 字号 评论关闭

效果图如下:

第一页:

第二页:

实现方法如下:

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<?
global $start;
require('../include/common.ini');
require('../class/mysql.class.php');
require('../class/page.class.php');
require('../fun/fun_pinyin.php');
$db =new mysql_db;
$db->sql_connect($db_host,$db_username,$db_userpass,$db_database);
$onepage =5;
$sql = "select id from successpic";
$query =$db->query($sql);
$num = $db->get_num_rows($query);
$allpages = ceil ($num / $onepage);

 

for ($x = 0;$x<$allpages; $x++){

for ($y = 0;$y<$allpages; $y++){
if ($y == 0){
$list1 .= '<a href="indexp.html" >第'.$y.'页  </a>|';
} else {
$list1 .= "<a href='index_".$y.".html' >第".$y."页  </a>|";
}
}

$start = $x * $onepage;

$sql1 = "select * from successpic order by id desc limit $start,$onepage";
//$start=null;
$result1=$db->query($sql1);
$tupian=$db->get_num_rows($result1);

while($row=$db->fetch_row($result1))
 {
   $title[$x][]=$row['title'];
  $address[$x][]=$row['address'];
  $psrc[$x][]=$row['psrc'];
  $content[$x][]=$row['content'];
 }
$result1=null;
$row=null;
ob_start();

?>
<?

 

 ?>   
<script language="JavaScript"> 
<!-- 
//图片按比例缩放 
var flag=false; 
function DrawImage(ImgD){ 
 var image=new Image(); 
 var iwidth = 150;  //定义允许图片宽度 
 var iheight = 150;  //定义允许图片高度 
 image.src=ImgD.src; 
 if(image.width>0 && image.height>0){ 
 flag=true; 
 if(image.width/image.height>= iwidth/iheight){ 
  if(image.width>iwidth){   
  ImgD.width=iwidth; 
  ImgD.height=(image.height*iwidth)/image.width; 
  }else{ 
  ImgD.width=image.width;   
  ImgD.height=image.height; 
  } 
  ImgD.alt=image.width+"×"+image.height; 
  } 
 else{ 
  if(image.height>iheight){   
  ImgD.height=iheight; 
  ImgD.width=(image.width*iheight)/image.height;   
  }else{ 
  ImgD.width=image.width;   
  ImgD.height=image.height; 
  } 
  ImgD.alt=image.width+"×"+image.height; 
  } 
 } 
}  
//--> 
</script>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>金思维</title>
<link href="../html/images/css/style.css" rel="stylesheet" type="text/css" />
</head>

<body>
<table width="1007" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td width="767" height="3" bgcolor="#000000"></td>
    <td width="172" height="3" bgcolor="#CCCCCC"></td>
    <td width="68" height="3" bgcolor="#000000"></td>
  </tr>
</table>
<table width="1007" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td width="251" align="right"><a href="index.html"><img src="../html/images/logo.jpg" width="185" height="97" border="0" /></a></td>
    <td width="1" align="center" bgcolor="E7E7E7">&nbsp;</td>
    <td width="687"><table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td height="51" valign="top"><div id="s1">加入收藏        设为首页</div></td>
      </tr>
      <tr>
        <td height="46"><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="687" height="46">
          <param name="movie" value="../html/images/flash/menu.swf" />
          <param name="quality" value="high" />
          <embed src="../html/images/flash/menu.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="687" height="46"></embed>
        </object></td>
      </tr>
    </table></td>
    <td width="68" class="bj">&nbsp;</td>
  </tr>
</table>
<table width="1007" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td height="1" bgcolor="#E7E7E7"></td>
  </tr>
  <tr>
    <td><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="1007" height="251">
      <param name="movie" value="../html/images/flash/4.swf" />
      <param name="quality" value="high" />
      <embed src="../html/images/flash/4.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="1007" height="251"></embed>
    </object></td>
  </tr>
</table>
<table width="1007" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td width="252" align="right" valign="top"><table width="174" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td width="1" bgcolor="#CCCCCC"></td>
        <td width="172" valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td><img src="../html/images/anli.jpg" width="172" height="79" /></td>
          </tr>
        </table>
          <table width="100%" border="0" cellpadding="0" cellspacing="0">
            <tr onMouseOver="this.className='cl1';" onMouseOut="this.className='cl2'"bgcolor="#A4CD95"class="cl">
              <td height="30" align="left" class="font4"><a href="<?=Pinyin('典型用户',1).'.html'?>">典型用户</a></td>
            </tr>
            <tr >
              <td height="1" align="left" bgcolor="#E3E3E3"></td>
            </tr>
            <tr onMouseOver="this.className='cl1';" onMouseOut="this.className='cl2'"bgcolor="#A4CD95"class="cl">
              <td height="30" align="left" class="font4"><a href="indexp.html">相关合影</a></td>
            </tr>
            <tr >
              <td height="1" align="left" bgcolor="#E3E3E3"></td>
            </tr>
            <tr onMouseOver="this.className='cl1';" onMouseOut="this.className='cl2'"bgcolor="#A4CD95"class="cl">
              <td height="30" align="left" class="font4"><a href="#"></a></td>
            </tr>
            <tr >
              <td height="1" align="left" bgcolor="#E3E3E3"></td>
            </tr>
            <tr onMouseOver="this.className='cl1';" onMouseOut="this.className='cl2'"bgcolor="#A4CD95"class="cl">
              <td height="30" align="left" class="font4"><a href="#"></a></td>
            </tr>
            <tr >
              <td height="1" align="left" bgcolor="#E3E3E3"></td>
            </tr>
          </table>
          <table width="100%" border="0" cellspacing="5" cellpadding="3">

            <tr>
              <td align="center"><img src="../html/images/index2_r9_c3.gif" width="152" height="36" /></td>
            </tr>
            <tr>
              <td align="center"><img src="../html/images/index2_r11_c3.gif" width="152" height="37" /></td>
            </tr>
            <tr>
              <td align="center"><img src="../html/images/index2_r13_c3.gif" width="152" height="37" /></td>
            </tr>
          </table>
          <table width="100%" border="0" cellspacing="0" cellpadding="0">
            <tr>
              <td valign="bottom"><table width="100%" border="0" cellpadding="0" cellspacing="0" class="bj1">
                <tr>
                  <td height="30">&nbsp;</td>
                </tr>
              </table></td>
            </tr>
            <tr>
              <td><table width="96%" border="0" cellspacing="5" cellpadding="3">
                <tr>
                  <td align="left"><span class="font">售后热线 0731-5078995<br />
  销售热线 0731-5078877<br />
                  </span>客户投诉 0731-5078995<br />
  传    真 0731-5078995<br />
  E-mail: jswkj@jswkj.com<br />
  地   址:湖南长沙市五一<br />
  路105号(比云天大厦)</td>
                </tr>
               
              </table></td>
            </tr>
          </table></td>
        <td width="1" height="1000" bgcolor="#CCCCCC"></td>
      </tr>
    </table></td>
    <td valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td width="686" valign="top" class="bj2"><table width="100%" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td width="73%">&nbsp;</td>
            <td width="27%" height="50"><a href="index.html">首页</a> &gt;&gt; 成功案例 &gt;&gt; <span class="font">相关合影</span></td>
          </tr>
        </table>
          <table width="96%" border="0" align="center" cellpadding="0" cellspacing="5" class="bk7">
            <tr>
              <td><span class="font02">金思维的理念和综旨</span><br />
                金思维不断的 吸收新知和创新,关注与客户长期的相互支持与合作,打破传统的 销售服务理念,为每一个客户量身定制跟踪的技术服务方案,始终 坚持用户的成功和满意,是我们长远发展的强有力保障。 </td>
            </tr>
          </table>
          <table width="100%" border="0" cellspacing="0" cellpadding="0">
            <tr>
              <td>&nbsp;</td>
            </tr>
            <tr>
              <td height="1" bgcolor="#E1E1E1"></td>
            </tr>
          </table>
          <table width="96%" border="0" align="center" cellpadding="0" cellspacing="0">
            <tr>
              <td>&nbsp;</td>
            </tr>
            <tr>
              <td height="40" class="font9">相关合影</td>
            </tr>
            <tr>
              <td><table width="100%" border="0" cellpadding="0" cellspacing="2" bgcolor="#BD6A0E">
                  <tr>
                    <td width="12%" height="3"></td>
                    <td width="88%" height="3" bgcolor="#FFFFFF"></td>
                  </tr>
              </table></td>
            </tr>
          </table>
 
   
<!-----------------图片列表显示----------------------------->   
   
          <table width="96%" border="0" align="center" cellpadding="0" cellspacing="8">
   
<?
for($i=0;$i<=$tupian;$i++)
{
echo "<tr>";
for($j=$i;$j<=$i+3;$j++)
{
if ($j>$tupian-1) {
  break;

}else{
echo "<td align='center'><A href='../".$psrc[$x][$j]."' title='".$title[$x][$j]."'><img src='".$address[$x][$j]."' onload = 'DrawImage(this)' border=0 alt='".$title[$x][$j]."'/><br>".$title[$x][$j]."</a><br> $j </td>";
}
}
echo"</tr>";
$i=$i+3;
//echo "<br>";
}
?>
   
<div>
<? 

echo $list1;

$list1=null; 
?> 
 
  </div>
          </table>
   
   
   
   
    </td>
        <td width="1" height="520" bgcolor="#E7E7E7"></td>
      </tr>
    </table>    </td>
    <td width="68" class="bj">&nbsp;</td>
  </tr>
</table>
<table width="1007" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td width="75" height="1" bgcolor="#CCCCCC"></td>
    <td width="160" height="1"></td>
    <td width="716" height="1" bgcolor="#CCCCCC"></td>
  </tr>
</table>
<table width="900" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td height="18"></td>
  </tr>
</table>
<table width="1007" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td height="1" colspan="7" bgcolor="#CCCCCC"></td>
  </tr>
  <tr>
    <td width="78" bgcolor="#F6F6F6"></td>
    <td width="1" bgcolor="#CCCCCC"></td>
    <td width="172" height="80" bgcolor="#FFFFFF"><table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
      <tr>
        <td width="17%" align="center"><img src="../html/images/ico9.gif" width="5" height="5" /></td>
        <td width="83%">友情连接</td>
      </tr>
      <tr>
        <td colspan="2" align="center"><select name="select">
          <option>----------------</option>
        </select>        </td>
      </tr>
    </table></td>
    <td width="1" bgcolor="#CCCCCC"></td>
    <td width="680" align="center" bgcolor="#FFFFFF"><span class="font1">版权所有:长沙新友软件开发有限公司 <br />
      地址:长沙市解放东路38号华瑞电子大厦B座1805室(赛博数码广场北栋) <br />
    在线咨询QQ:200873178 总机:0731-2919501 2919502 2919503 2919506 </span><br /></td>
    <td width="1" bgcolor="#CCCCCC"></td>
    <td width="65" bgcolor="#F6F6F6"></td>
  </tr>
</table>
</body>
</html>

 

<?
$temp = ob_get_contents();

ob_end_clean();
 
if ($x == 0){
$indexpath = "../news/indexp.html";
} else {
$indexpath = "../news/index_".$x.".html";
}

 $title[]=null;
  $address[]=null;
  $psrc[]=null;
  $content[]=null;

 

if (is_file ($indexpath)){
@unlink ($indexpath); //若文件已存在,则删除
}
$handle = fopen ($indexpath,"w"); //打开文件指针,创建文件
/*
  检查文件是否被创建且可写
*/
if (!is_writable ($indexpath)){
echo "文件:".$indexpath."不可写,请检查其属性后重试!"; //修改为echo
}
if (!fwrite ($handle,$temp)){ //将信息写入文件
echo "生成文件".$indexpath."失败!"; //修改为echo
}
fclose ($handle); //关闭指针
$temp=null;

}
echo("<script>alert('成功生成静态文件!');history.go(-1);</script>");
?>

上面为整个页面的代码:

主要是用ob来控制html文件源代码的获取,然后通过基本文件操作来实现html文件生成.

 

抱歉!评论已关闭.