Big Brother PHP Master, little brother I just learned PHP, in the generation of static paging encountered a problem, is the problem of anti-page, I hope you can give a beautiful full page flip code, thank you!
<title>PHP generation static HTML Paging implementation method</title>
$conn =mysql_connect (' localhost ', ' root ', ' 123456 ')
Or Die (' Connection failed: '. mysql_error ());
Select data table
if (mysql_select_db (' BBS ', $conn))
{
Echo ' Select Database Success! '.'
';
}
Else
{
Echo ' Database selection failed! '. 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)) {
If it does not exist, establish
mkdir ($filedir, 0777);
}
for ($i = 0; $i < $allpages; $i + +) {
if ($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 ']. '
';
}
$content 1 = str_replace ("{articletable}", $list. $i, $content);
Page out
$list 1 = ";
for ($j = 0; $j < $allpages; $j + +) {
if ($j = = 0) {
$list 1. = ' $j '. ' page | ';
} else {
$list 1. = "No.". $j. " Page | ";
}
}
$content 2 = Str_replace ("{mune}", $list 1, $content 1);
if (Is_file ($indexpath)) {
@unlink ($indexpath); If the file already exists, delete the
}
$handle = fopen ($indexpath, "w"); Open file pointer, create file
/*
Check if the file is created and writable
*/
if (!is_writable ($indexpath)) {
echo "File:". $indexpath. " Not writable, please check its properties and try again! "; Modify to Echo
}
if (!fwrite ($handle, $content 2)) {//write information to file
echo "Generate file". $indexpath. " Failed! "; Modify to Echo
}
Fclose ($handle); Close pointer
}
Fclose ($fp);d IE ("raw page file completion, such as incomplete, please check the file permissions system and regenerate!") ");
?>
------Solution--------------------
/*
$FP =fopen ("tmp.htm", "R");//read-only open template
$str =fread ($fp, FileSize ("tmp.htm"));//Read the contents of the template
Replace what you want to replace with the content to be generated
$str =str_replace ("{title}", ' new title ', $STR)//replace title with new title
$str =str_replace ("{content}", ' New content ', $str);//replace content with new contents
Fclose ($FP);//Close file
$handle =fopen (' news.htm ', ' w ');//write to open News path
Fwrite ($handle, $STR);//write the content you just replaced into the generated HTM file
Fclose ($handle);
echo "Build Success";
*/
Batch Build
$row =array ("News title", "News content"), Array ("News title 2", "News content 2");//two-dimensional array
foreach ($row as $id = = $val) {
$title = $val [0];
$content = $val [1];
$path = $id. '. HTM ';
$FP =fopen ("tmp.htm", "R");//read-only open template
$str =fread ($fp, FileSize ("tmp.htm"));
$str =file_get_contents ("tmp.htm", "R");