自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

使用相關(guān)函數(shù)實(shí)現(xiàn)PHP處理分頁

開發(fā) 后端
PHP處理分頁首先要做的就是查詢出需要分頁的需求,比如總頁數(shù)和每頁篇數(shù)等。然后在通過對(duì)PHP語言的靈活運(yùn)用獲取頁面元素,進(jìn)行分頁。

通過對(duì)PHP語言的深入學(xué)習(xí)可以知道,其是一個(gè)功能非常強(qiáng)大的語言,應(yīng)用領(lǐng)域也非常廣泛。比如今天我們介紹的分頁問題,利用PHP處理分頁,就能得到一個(gè)良好的結(jié)果。#t#

如我們指定分頁時(shí),每頁20篇。某子頻道列表內(nèi)文章經(jīng)數(shù)據(jù)庫查詢?yōu)?5條,則,首先我們通過查詢得到如下參數(shù):1,總頁數(shù);2,每頁篇數(shù)。

PHP處理分頁第二 步,for ($i = 0; $i < allpages; $i++),頁面元素獲取,分析,文章生成,都在此循環(huán)中執(zhí)行。不同的是,die ("創(chuàng)建文件".$filename."成功!";這句去掉,放到循環(huán)后的顯示,因?yàn)樵撜Z句將中止程序執(zhí)行。例:

  1. < ?php  
  2. $fp = fopen ("temp.html","r");  
  3. $content = fread ($fp,filesize ("temp.html"));  
  4. $onepage = '20';  
  5. $sql = "select id from article where 
    channel='$channelid'"
    ;  
  6. $query = mysql_query ($sql);  
  7. $num = mysql_num_rows ($query);  
  8. $allpages = ceil ($num / $onepage);  
  9. for ($i = 0;$i<$allpages; $i++){  
  10. if ($i == 0){  
  11. $indexpath = "index.html";  
  12. } else {  
  13. $indexpath = "index_".$i."html";  
  14. }  
  15. $start = $i * $onepage;  
  16. $list = '';  
  17. $sql_for_page = "select name,filename,title 
    from article where channel='$channelid'
     limit $start,$onepage"
    ;  
  18. $query_for_page = mysql_query ($sql_for_page);  
  19. while ($result = $query_for_page){  
  20. $list .'<a href='.$root.$result['filename']
    .' 
    target=_blank>'.$title.'</a><br>';  
  21. }  
  22. $content = str_replace ("{articletable}
    ",$list,$content);  
  23. if (is_file ($indexpath)){  
  24. @unlink ($indexpath); //若文件已存在,則刪除  
  25. }  
  26. $handle = fopen ($indexpath,"w"); 
    //打開文件指針,創(chuàng)建文件  
  27. /*  
  28. 檢查文件是否被創(chuàng)建且可寫  
  29. */  
  30. if (!is_writable ($indexpath)){  
  31. echo "文件:".$indexpath."不可寫,
    請(qǐng)檢查其屬性后重試!"; //修改為echo  
  32. }  
  33. if (!fwrite ($handle,$content)){ //將信息寫入文件  
  34. echo "生成文件".$indexpath."失?。?quot;; //修改為echo  
  35. }   
  36. fclose ($handle); //關(guān)閉指針  
  37. }  
  38. fclose ($fp);  
  39. die ("生成分頁文件完成,如生成不完全,
    請(qǐng)檢查文件權(quán)限系統(tǒng)后重新生成!");  
  40. ?> 

大致PHP處理分頁的思路如此,其中如其它數(shù)據(jù)生成,數(shù)據(jù)輸入輸出檢查,分頁內(nèi)容指向等可酌情在頁面中加入。

責(zé)任編輯:曹凱 來源: 百度博客
相關(guān)推薦

2009-12-10 10:18:05

PHP讀取文件

2023-03-20 08:14:11

PHP類型轉(zhuǎn)換

2009-12-11 14:16:13

PHP獲取字段長度

2009-11-25 09:56:06

PHP數(shù)組處理函數(shù)

2009-12-03 09:49:59

PHP分頁導(dǎo)航函數(shù)

2009-11-24 11:00:05

PHP函數(shù)Date()

2010-05-25 15:12:22

MySQL分頁

2009-11-30 17:16:34

PHP函數(shù)preg_m

2009-12-07 16:44:45

PHP圖形處理函數(shù)

2010-01-04 16:54:22

ADO分頁

2009-12-03 09:23:17

PHP長文章分頁函數(shù)

2009-12-02 18:51:12

PHP分頁類

2009-12-07 17:33:44

PHP SQlite數(shù)

2009-11-18 10:22:14

PHP substr

2009-12-03 09:00:18

PHP分頁函數(shù)

2009-12-01 12:50:21

PHP字符處理函數(shù)

2009-12-08 16:19:21

PHP函數(shù)pack

2009-12-03 19:23:15

PHP處理會(huì)話函數(shù)

2009-12-07 17:05:36

PHP函數(shù)imaget

2009-11-25 17:48:18

PHP文件系統(tǒng)相關(guān)函數(shù)
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)