PHP static html paging Implementation Method

Source: Internet
Author: User

<? PHP
$ Conn = mysql_connect ('localhost', 'root', 'wy ')
Or die ('Connection failed: '. mysql_error ());

// Select a data table
If (mysql_select_db ('mynews', $ conn ))
{
Echo: the database is selected! '.' <P> ';

}
Else
{
Echo 'database selection failed! '. Mysql_error ().' <p> ';
}
@ Header ("Content-Type: text/html; charset = UTF-8 ");
Mysql_query ("set names 'utf8 '");

$ Fp = fopen ("temp.html", "R ");
$ Content = fread ($ FP, filesize ("temp.html "));
$ Onepage = 2;
$ SQL = "select ID from News ";
$ Query = mysql_query ($ SQL );
$ Num = mysql_num_rows ($ query );
$ Allpages = Ceil ($ num/$ onepage );
For ($ I = 0; $ I <$ allpages; $ I ++ ){
If ($ I = 0 ){
$ Indexpath = "index.html ";
} Else {
$ Indexpath = "index _". $ I. ". html ";
}
$ Start = $ I * $ onepage;
$ List = '';
$ SQL _for_page = "select * from news limit $ start, $ onepage ";
$ Result = mysql_query ($ SQL _for_page );
While ($ ROW = mysql_fetch_array ($ result ))
{
$ List. = 'uid = '. $ row ['id']. $ row ['title'].' <br> ';
}
$ Content1 = str_replace ("{articletable}", $ list. $ I, $ content );
// Pagination
$ List1 = '';
For ($ J = 0; $ j <$ allpages; $ J ++ ){
If ($ J = 0 ){
$ List1. = '<a href = "index.html"> page'. $ J. '</a> | ';
} Else {
$ List1. = "<a href = 'index _". $ J. ". html"> page ". $ J." </a> | ";
}
}
$ Content2 = str_replace ("{mune}", $ list1, $ content1 );

If (is_file ($ indexpath )){
@ Unlink ($ indexpath); // delete a file if it already exists
}
$ Handle = fopen ($ indexpath, "W"); // open the file pointer and create a file
/*
Check whether the file is created and writable.
*/
If (! Is_writable ($ indexpath )){
Echo "file:". $ indexpath. "cannot be written. Check its attributes and try again! "; // Modify it to echo
}
If (! Fwrite ($ handle, $ content2) {// write information to the file
Echo "Generating File". $ indexpath. "failed! "; // Modify it to echo
}
Fclose ($ handle); // close the pointer
}
Fclose ($ FP );
Die ("generation of paging files is complete. If the generation is incomplete, check the File Permission System and generate a new one! ");
?>

Temp.html


{Title}

This Is A {file} file's templets
{ articletable}
paging {mune}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.