学而时习之

静坐当思己过,闲谈莫论人非

  IT博客 :: 首页 :: 联系 :: 聚合  :: 管理
  11 Posts :: 1 Stories :: 2 Comments :: 0 Trackbacks
本程序作用是从PHP生成HTML静态页面并存储到以年份和月份为名称创建的目录。读取全部数据批量生成,全部生成后弹出提示。可指定批次生成数量,建议不超过800,否则执行速度会有问题。为cd2sc.com网站功能而开发,代码为本人原创,生成速度一般。
(出于众所周知的原因,涉及到数据库的数据字段名称做了改动,并且为了代码明晰去掉了参数过滤的部分)

说明:原动态地址为 moban.php?id=1 ,生成后地址为 html/200808/sell_1.html 。page.php为分页程序,本博客中有发布。
页面使用方式,将本代码保存为make.php,使用方法为浏览器访问 make.php?t=数量&pg=页面;例如 make.php?t=300&pg=2,即每次生成300条数据,从数据列表第2页开始生成,即跳过前面300条。如果不加任何参数,直接访问make.php,则默认每次生成200条,从第一页开始生成。

 1<?php
 2if($_GET[pg]==''){
 3$aa=1;
 4}else{
 5$aa=$_GET[pg];
 6}
 7include("admin/conn.php");
 8require_once("page.php");
 9$result=mysql_query("select * from 2carsell ");
10$totle=mysql_num_rows($result);
11$pagelist = $_GET[t];
12if($_GET[t]==''){
13$pagelist='200';
14}else{
15$pagelist=$_GET[t];
16}
17$pager = new Pager($totle,$pagelist);
18$datastat=" 共 <b>".$pager->countall."</b> 条,每次生成 <b>".$pager->countlist."</b> 条,共需生成 <b>".$pager->page."</b> 次";//数据统计
19$bb=$pager->page;
20$pagenav=$pager->backstr.$pager->thestr.$pager->nextstr;
21$limitFrom  = $pagelist*($pager->pg-1);
22$result=mysql_query("select * from 2carsell ORDER BY id DESC limit $limitFrom,$pagelist"); 
23?>
24<center><div style="font-size:14px;"><b>第 <font color=red><?echo $aa?></font > 次页面生成中..<? echo $datastat?></b></div><br>
25<?
26print "<center><textarea name=textarea class=textarea style='width:520px;height:455px'>";
27while($datauser=mysql_fetch_array($result)){
28
29$iid=$datauser[id];
30$html = file_get_contents("/moban.php?id=".$iid."");
31$sql="select * from 2carsell where id=$iid";
32$data=mysql_fetch_array(mysql_query($sql));
33$path=date("Ym",$data[PutDate]);
34$testdir="html/".$path
35if(file_exists ($testdir)): 
36else: 
37mkdir ($testdir, 0777); 
38echo "目录".$testdir."创建成功!<br>";
39endif
40
41
42$filename = "html/$path/sell_$iid.html";
43
44// 使用写入模式打开$filename
45if (!$handle = fopen($filename, 'w')) {
46   print "不能打开文件 $filename";
47   exit;
48}
49
50 if (is_writable($filename)) {
51
52// 将$html写入到我们打开的文件中。
53if (!fwrite($handle, $html)) {
54  print "不能写入到文件 $filename";
55  exit;
56}
57
58print "文件 $filename 更新成功!\n\r";
59
60fclose($handle);
61
62else {
63print "文件 $filename 不可写";
64}
65?>
66 <? }?>
67 </textarea>
68 <br><br>
69 
70
71
72 <div style="font-size=12px"><? echo $datastat."&nbsp;&nbsp;"?></div><br><br>
73 <?
74 $aa=$aa+1;
75 if($aa>$bb){
76 echo '<font color=blue>恭喜,所有页面生成完毕!</font>';
77 echo "<script>alert('所有文档生成/更新完毕!')</script>";
78 }else{
79 echo "<Script> window.location='make.php?t=$pagelist&pg=$aa'; </script>";
80 }
81 ?>
posted on 2008-08-28 16:49 吟游诗人 阅读(336) 评论(0)  编辑 收藏 引用 所属分类: CD2SC.com网站开发相关
只有注册用户登录后才能发表评论。