Smarty Pagination Implementation method Complete instance _php instance

Source: Internet
Author: User
Tags php template prev smarty template

The example of this article describes the Smarty paging implementation method. Share to everyone for your reference, specific as follows:

First is the PHP file section:

<?php require ("include.php"); Contains the Smarty configuration part require ' conn.php '; Contains the database configuration section $pagesize = 10;
Set 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 statistical data $pages = $num/$pagesize; $pages =ceil ($pages);
 Find out how many pages are 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 label on the previous page next page with NULL.
 $pageup = "";
$pagedown = "";
 }else{switch ($pageval) {Case 1: {$pageup = "Home page"; $pagedown = "<a href= $url page=". ($pageval + 1). "
 > next page </a> ";
 Break } default: {$pageup = "<a href= $url? page=". ( $pageval-1). "
 > Prev </a> "; $pagedown = "<a href= $url page=". ($pageval + 1). "
   > next page </a> ";
 Break Case $pages: {$pageup = "<a href= $url? page=". ( $pageval-1). "
 > Prev </a> ";
 $pagedown = "Last page";
  Break }} $smarty->assign ("Pageconfig", $pagEconfig);    ================================================== $sql _list= "select * from ' wp_links ' LIMIT $page, $pagesize";
This control data shows the quantity part $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 ']);
Re-assign the query content in the database} $pageconfig = "Current page $pageval, 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 following is the writing section for the template:

<table>
 <tr>
 <td>id</td>
 <td>url</td>
 <td>name</ Td>
 </tr>
{section name=list loop= $title}
 <tr>
 <td>{$title [list].id}</td >
 <td>{$title [list].url}</td>
 <td>{$title [list].name}</td>
 </tr >
{/section}
 </table>
{$pageup} {$pagedown} {$pageconfig}

More interested in smarty related content readers can view the site topics: "Smarty Template Primer Tutorial", "PHP Template Technology Summary", "PHP based on PDO Operation Database Skills summary", "PHP Operations and Operator Usage Summary", "PHP Network Programming Skills Summary", " Introduction to PHP Basic Grammar, "Introduction to PHP object-oriented programming", "PHP string (String) Usage Summary", "Php+mysql Database Operations Tutorial" and "PHP common database Operation Skills Summary"

I hope this article will help you with the PHP program design based on Smarty template.

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.