Complete implementation of Smarty paging: example of smarty paging _ PHP Tutorial

Source: Internet
Author: User
A complete example of the Smarty paging implementation method is provided. The Smarty paging implementation method is a complete example. The smarty paging instance in this article describes the implementation method of Smarty paging. For your reference, see the following: the first part is the php file: the complete implementation of the Smarty paging method instance and the smarty paging instance.

This article describes how to implement Smarty paging. We will share this with you for your reference. The details are as follows:

The first part is the php file:

<? Phprequire ("include. php "); // contains the require 'Conn in the smarty configuration section. php '; // contains the database configuration section $ pagesize = 10; // sets the number of data displayed per page $ url = $ _ SERVER ['request _ URI']; $ url = parse_url ($ url); $ url = $ url ['path']; $ SQL = "SELECT * FROM 'WP _ links '"; $ db_list = mysql_query ($ SQL); $ num = mysql_num_rows ($ db_list); // Total statistics $ pages = $ num/$ pagesize; $ pages = ceil ($ pages ); // find the total number of pages required to display if ($ _ GET ['Page']) {$ pageval =$ _ GET ['Page']; $ page = ($ pageval-1) * $ pagesize;} if ($ Num> $ pagesize) {if (! Isset ($ pageval) $ pageval = 1;} if ($ pages = 1) {// if the total page has only one page, replace the tag of "previous page" and "next page" with null. $ Pageup = ""; $ pagedown = "";} else {switch ($ pageval) {case 1: {$ pageup = "homepage"; $ pagedown = "next page "; break;} default: {$ pageup = "previous page"; $ pagedown = "next page"; break;} case $ pages: {$ pageup = "previous page "; $ pagedown = "Last page"; break ;}}$ smarty-> assign ("pageconfig", $ pageconfig ); // ================================================ =============$ SQL _list = "SELECT * FROM 'WP _ links 'LIMIT $ page, $ pagesize "; // This controls the number of data displayed. $ db_list_list = mysql_query ($ SQL _list); while ($ row = mysql_fetch_array ($ db_list_list) {$ page_list [] = array ("id" => $ row ['link _ id'], "url" => $ row ['link _ url'], "name" => $ row ['link _ name']); // revalue the query content in the database} $ pageconfig = "current $ pageval page, total $ pages page"; $ smarty-> assign ("pageconfig", $ pageconfig ); $ smarty-> assign ("pageup", $ pageup); $ smarty-> assign ("pagedown", $ pagedown); $ smarty-> assign ("title ", $ page_list); $ smarty-> display ("index.htm");?>

The template is written as follows:

 
 {section name=list loop=$title} 
   {/section} 
  
id url name
{$title[list].id} {$title[list].url} {$title[list].name}
{$pageup}{$pagedown}{$pageconfig}

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.