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.