學習重點:
1.LIMIT 用法
2.各種參數
3.超連結呼叫
第一:先在檔案中設定數字分頁模組;我的檔案是(blog.php)
<span>//</span><span>分页模块</span><span>$_page</span> = <span>$_GET</span>['page'<span>]; </span><span>$_pagesize</span> = 10<span>; </span><span>$_pagenum</span> = (<span>$_page</span> - 1) * <span>$_pagesize</span><span>; </span><span>//</span><span>首页要得到所有的数据总和</span><span>$_num</span>=<span>mysql_num_rows</span>(_query("SELECT tg_id FROM tg_user"<span>)); </span><span>$_pageabsolute</span>=<span>$_num</span> / <span>$_pagesize</span>;
要注意的是在資料庫中取集的時候
//我們必須每次重新讀取結果集,而不是從新去執行SQL語句。
$_result = _query("SELECT tg_username,tg_sex,tg_face FROM tg_user ORDER BY tg_reg_time DESC LIMIT $_pagenum,$_pagesize");
在其中可能會因為編碼出現容錯誤,解決的方法是
<span><div> <ul> <?php <span>for</span>(<span>$i</span>=0;<span>$i</span><<span>$_pageabsolute</span>;<span>$i</span>++<span>){ </span><span>if</span> (<span>$_page</span> == (<span>$i</span>+1<span>)) { </span><span>echo</span> '<li><a href="blog.php?page='.(<span>$i</span>+1).'">'.(<span>$i</span>+1).'</a></li>'<span>; }</span><span>else</span><span>{ </span><span>echo</span> '<li><a href="blog.php?page='.(<span>$i</span>+1).'">'.(<span>$i</span>+1).'</li>'<span>; } } </span>?> </ul> </div></span>
以上就介紹了PHP自練計畫之數字分頁效果,包含了方面的內容,希望對PHP教學有興趣的朋友有所幫助。