PHP self-training project: Digital paging effect; php Training Project pagination
Learning points:
1. LIMIT usage
2. Various parameters
3. hyperlink call
First, set the digital paging module in the file. My file is (blog. php)
// Paging module $ _ page =$ _ GET ['page']; $ _ pagesize = 10; $ _ pagenum = ($ _ page-1) * $ _ pagesize; // obtain the total data on the home page $ _ num = mysql_num_rows (_ query ("SELECT tg_id FROM tg_user"); $ _ pageabsolute =$ _ num/$ _ pagesize;
It should be noted that when the set is retrieved in the database
// We must re-read the result set each time instead of executing the SQL statement again.
$ _ Result = _ query ("SELECT tg_username, tg_sex, tg_face FROM tg_user order by tg_reg_time desc limit $ _ pagenum, $ _ pagesize ");
Set the effect of pagination Loop
<div id="page_num"> <ul> <?php for($i=0;$i<$_pageabsolute;$i++){ if ($_page == ($i+1)) { echo '<li><a href="blog.php?page='.($i+1).'" class="selected">'.($i+1).'</a></li>'; }else{ echo '<li><a href="blog.php?page='.($i+1).'">'.($i+1).'</li>'; } } ?> </ul> </div>
Corresponding CSS
#page_num {height:20px;clear:both;padding:10px 0;position:relative;}#page_num ul {position:absolute;right:30px;height:20px;}#page_num ul li {float:left;width:26px;height:20px;}#page_num ul li a {display:block;width:20px;height:20px;line-height:20px;border:1px solid #333;text-align:center;text-decoration:none;}#page_num ul li a:hover,#page_num ul li a.selected {background:#666;font-weight:bold;color:#fff;}