生成列表页分页的HTML静态页
<?php header( 'Content-Type:text/html;charset=utf-8'); $db = mysql_connect("localhost","root","123456"); $re = mysql_select_db("child_games", $db); $sql = "select id, name from cdb_classedit"; $res = mysql_query($sql); $row = mysql_num_rows($res); $pagesize = 10; //每页显示条数 if($row < $pagesize) { $pages = 1; //总页数 } if($row % $pagesize) { $pages = (int)($row / $pagesize + 1); //有余数就多加一页 } else { $pages = (int)($row / $pagesize); //整除,不做调整 } for($i = 1; $i <= $pages; $i++) { $page_turn = ""; if($i == 1) { $indexpath = "index.html"; $page_turn .= "首页 | 上一页"; } else { $indexpath = "index_" . $i . ".html"; $page_turn .= "<a href='index.html'>首页</a> | <a href='index_" . ($i - 1) . ".html'>上一页</a>"; } if($i == $pages) { $page_turn .= " | 下一页 | 末页"; } else { $page_turn .= " | <a href='index_" . ($i + 1) . ".html'>下一页</a> | <a href='index_" . $pages . ".html'>末页</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_object($result); $id = $doc->id; $title = $doc->name; $list .= "<a href = '" . $id . ".html'>$title</a><br>"; $j++; } $list .= "<br><br>" . $page_turn; $handle = fopen("./App/html/".$indexpath, "a+"); echo $list . "<br><br>"; fwrite($handle, $list); fclose($handle); } //把index.html复制拷贝成index_1.html copy("./App/html/index.html", "./App/html/index_1.html"); ?>