찾다
백엔드 개발PHP 튜토리얼PHP 스마트 페이징 원리 및 페이징 코드 공유

  1. include_once("smarty.class.php");

  2. class smartyproject extendssmarty
  3. {
  4. 함수 __construct()
  5. {
  6. $this->config_dir="smarty/smarty/config_file.class.php";

  7. $this->caching=false;
  8. $this->template_dir = "smarty/templates/";
  9. $this->cache_dir = "smarty/smarty_cache/";
  10. $ this->left_delimiter = "{";
  11. $this->right_delimiter = "}";
  12. }
  13. }
  14. ?>
复主代码

2,adodb,连接数据库类:

  1. class conndb
  2. {
  3. var $dbtype;
  4. var $host;
  5. var $user;
  6. var $ pwd;
  7. var $dbname;
  8. var $debug;//false不显示侦错信息,反之,显示
  9. var $conn;
  10. function __construct($dbtype,$host,$user, $pwd,$dbname,$debug=false)
  11. {
  12. $this->dbtype = $dbtype;
  13. $this->host = $host;
  14. $this->user = $user;
  15. $this->pwd = $pwd;
  16. $this->dbname = $dbname;
  17. $this->debug = $debug;
  18. }
  19. //사용 가능한 정보(个人理解可以说返回adodb对象)
  20. function getconnid()
  21. {
  22. include_once('adodb5/adodb.inc.php');
  23. 만약에 ($this->dbtype == "mysql" || $this->dbtype == "mssql")
  24. {
  25. if($this->dbtype == "mysql")
  26. {
  27. $this->conn = newadoconnection("mysql");//创建adodb对象,声明数据库类型为mysql
  28. }
  29. else
  30. {
  31. $this->conn = newadoconnection("mssql");
  32. }
  33. $this->conn->connect($this->host,$this->user,$this->pwd,$this- >dbname);
  34. }
  35. else if($this->dbtype == "access")
  36. {
  37. $this->conn = newadoconnection("access") ;
  38. $this->conn->connect("driver={microsoft 액세스 드라이버(*.mdb)};dbq=".$this->dbname.";uid=".$this-> ;user.";pwd=".$this->pwd.";");
  39. }
  40. $this->conn->execute("이름 설정 utf-8") ;
  41. if($this->dbtype == "mysql")
  42. {
  43. $this->conn->debug = $this->debug;
  44. }
  45. return $this->conn;
  46. }
  47. function closeconnid()//关闭与数据库的连接
  48. {
  49. $this->conn->disconnection( );
  50. }
  51. }
复主代码

3,数据库操작类:

  1. class admindb
  2. {
  3. var $sqlstr;
  4. var $conn;
  5. var $sqltype;
  6. var $ rs;
  7. var $array;
  8. 함수 execsql($sqlstr,$conn)
  9. {
  10. $rs = $conn->execute($sqlstr);
  11. $sqltype = strtolower( substr(trim($sqlstr),0,6)); //strtolower() 函数把字符串转换为小写。
  12. if($sqltype = "select")
  13. {
  14. $array = $rs->getrows(); // 类似mysql_fetch_array函数返回的数组
  15. if(count($array) == 0 || $rs == false)
  16. {
  17. return false;
  18. }
  19. else
  20. {
  21. $array 반환;
  22. }
  23. }
  24. else if($sqltype = "update"||$sqltype = "insert"||$sqltype = "delete")
  25. {
  26. if($rs)
  27. {
  28. true를 반환;
  29. }
  30. else
  31. {
  32. false를 반환;
  33. }
  34. }
  35. }
  36. }
复代码

4, 구분:

  1. 클래스 페이지

  2. {
  3. var $rs;
  4. var $pagesize;
  5. var $ nowpage;
  6. var $array;
  7. var $conn;
  8. var $sqlstr;
  9. function showdate($sqlstr,$conn,$pagesize,$nowpage)
  10. {
  11. if( !isset($nowpage)||$nowpage=="")
  12. {
  13. $nowpage = 1 ;
  14. }
  15. else
  16. {
  17. $this->nowpage = $ nowpage;
  18. }
  19. $this->pagesize = $pagesize;
  20. $this->conn = $conn;
  21. $this->sqlstr = $sqlstr;
  22. $this ->rs = $this->conn->pageexecute($this->sqlstr,$this->pagesize,$this->nowpage);
  23. //pageexecute($sql, $nrows , $page, $inputarr=false) 使用资料集的页码功能,叁数 $page 是以 1 为启使值
  24. $this->array = $this->rs->getrows();
  25. if(count($this->array) == 0 || $this->rs == false)
  26. {
  27. return false;
  28. }
  29. else
  30. {
  31. return $this->array;
  32. }
  33. }
  34. function showpage($contentname,$utits,$anothersearchstr,$class)

  35. {
  36. $allrs=$this->conn->execute($this->sqlstr);

  37. $record=count($allrs->getrows());
  38. $pagecount=ceil($record/$this->pagesize);
  39. $str.="共有".$contentname." ". $record." ".$utits." 每页显示 ".$this->pagesize." ".$utits." 第 ".$this->rs ->absolutepage()." 页/共 ".$pagecount." 页";
  40. $str.="    ";

  41. if(!$this->rs->atfirstpage())

  42. {
  43. $str.="首页";
  44. }
  45. else
  46. {
  47. $str.="首页";
  48. }
  49. $str.=" ";
  50. if(!$this->rs->atfirstpage())

  51. {
  52. $str.="rs->absolutepage()-1).$anothersearchstr." class=".$class.">上一页";
  53. }
  54. else
  55. {
  56. $str.="上一页";
  57. }
  58. $str.=" "; p>
  59. if(!$this->rs->atlastpage())

  60. {
  61. $str.="rs->absolutepage() 1).$anothersearchstr." class=".$class.">下一页";
  62. }
  63. else
  64. {
  65. $str.="下一页";
  66. }
  67. $str.=" ";
  68. if(!$this->rs->atlastpage())

  69. {
  70. $str.="尾页";
  71. }
  72. else
  73. {
  74. $str.="尾页";
  75. }
  76. if(count($this->array)==0 || $this->rs==false)
  77. {
  78. return "";
  79. }
  80. else
  81. {
  82. return $str;
  83. }
  84. }
  85. }
复代码

5. 기사 문자 변환 처리를 위한 클래스:

  1. class usefun

  2. {
  3. function unhtml($text)
  4. {
  5. $content=(nl2br(htmlspecialchars($text)));//htmlspecialchars() 함수는 미리 정의된 일부 문자를 html 엔터티로 변환하고, nl2br() 함수는 문자열의 각 새 줄(/n) 앞에 삽입합니다. html 개행 문자().
  6. $content=str_replace("[strong]","",$content);

  7. $content=str_replace("[/strong]","
  8. ",$content);

  9. $content=str_replace("[em]","",$content);
  10. $content=str_replace("[/em]" ,"
  11. ",$content);
  12. $content=str_replace("[u]","",$content);
  13. $content=str_replace("[/u ]","
  14. ",$content);
  15. $content=str_replace("[font color=#ff0000]","", $content);
  16. $content=str_replace("[font color=#00ff00]","",$content);
  17. $content=str_replace("[font color= #0000ff]","",$content);
  18. $content=str_replace("[fontface=楷体_gb2312]","",$content);
  19. $content=str_replace("[fontface=宋体]","",$content);
  20. $content=str_replace(" [글꼴 얼굴=공식 스크립트]","",$content);
  21. $content=str_replace("[/font]","
  22. ",$content) ;
  23. //$content=str_replace(chr(32)," ",$content);
  24. $content=str_replace("[font size=1]","", $ content);
  25. $content=str_replace("[font size=2]","",$content);
  26. $content=str_replace("[font size=3] " ,"",$content);
  27. $content=str_replace("[font size=4]","",$content);
  28. $ content=str_replace("[글꼴 크기=5]","",$content);
  29. $content=str_replace("[글꼴 크기=6]","",$content);
  30. $content=str_replace("[fieldset][legend]","

    ",$content);
  31. $content=str_replace("[/legend]","
  32. ",$content);
  33. $content=str_replace("[/fieldset]","
  34. ", $ content);
  35. return $content;
  36. }
  37. }
코드 복사

위 생성 네 개의 모든 클래스는 하나의 클래스 파일 system.class.inc.php에 배치됩니다.

몇 가지 추가 파일: 1. 시스템.inc.php:

  1. session_start();

  2. include_once("smarty_inc.php");
  3. include_once("system.class.inc.php");
  4. //데이터베이스 연결 클래스 인스턴스화
  5. $connobj = new conndb("mysql","localhost","root","vertrigo"," db_fenye ",false);
  6. $conn = $connobj->getconnid();
  7. //데이터베이스 작업 클래스 인스턴스화
  8. $admindb = new admindb();
  9. //페이징 클래스 인스턴스
  10. $seppage=new seppage();
  11. //인스턴스화를 위해 공통 함수 클래스 사용
  12. $usefun=new usefun();
  13. //smarty 템플릿 호출
  14. $smarty=new smartyproject ();
  15. 함수 unhtml($params)
  16. {
  17. extract($params);
  18. $text=$content;
  19. global $usefun;
  20. return $usefun-> text);
  21. }
  22. $smarty->register_function("unhtml","unhtml");

  23. ?>
코드 복사

2、执行文件、index.php:

  1. include_once("system.inc.php");
  2. $arraybbstell = $admindb->execsql(" tb_bookinfo",$conn)에서 * 선택;
  3. if(!$arraybbstell)
  4. {
  5. $smarty->ass("isbbstell","t");
  6. }
  7. else
  8. {
  9. $smarty->할당("isbbstell",t);
  10. $smarty->할당("arraybbstell",$arraybbstell);
  11. }
  12. $arraybbs = $ seppage->showdate("select * from tb_bookinfo",$conn,1,$_get["page"]);
  13. if(!$arraybbs)
  14. {
  15. $smarty->할당( "isbbs",f);
  16. }
  17. else
  18. {
  19. $smarty->ass("isbbs",t);
  20. $smarty->assip(" showpage",$seppage->showpage("帖子","条","","a1"));
  21. $smarty->asse("arraybbs",$arraybbs);
  22. }
  23. $smarty->display("index.html");
  24. ?>
复system代码

3、解析文件,index.html:

  1. 椤垫ā
  2. PHP 스마트 페이징 원리 및 페이징 코드 공유
  3.  
    PHP 스마트 페이징 원리 및 페이징 코드 공유
  4.  
  5. {if $isbbs=="t"}
  6.   
성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
Laravel의 플래시 세션 데이터로 작업합니다Laravel의 플래시 세션 데이터로 작업합니다Mar 12, 2025 pm 05:08 PM

Laravel은 직관적 인 플래시 방법을 사용하여 임시 세션 데이터 처리를 단순화합니다. 응용 프로그램에 간단한 메시지, 경고 또는 알림을 표시하는 데 적합합니다. 데이터는 기본적으로 후속 요청에만 지속됩니다. $ 요청-

PHP 로깅 : PHP 로그 분석을위한 모범 사례PHP 로깅 : PHP 로그 분석을위한 모범 사례Mar 10, 2025 pm 02:32 PM

PHP 로깅은 웹 애플리케이션을 모니터링하고 디버깅하고 중요한 이벤트, 오류 및 런타임 동작을 캡처하는 데 필수적입니다. 시스템 성능에 대한 귀중한 통찰력을 제공하고 문제를 식별하며 더 빠른 문제 해결을 지원합니다.

PHP의 컬 : REST API에서 PHP Curl Extension 사용 방법PHP의 컬 : REST API에서 PHP Curl Extension 사용 방법Mar 14, 2025 am 11:42 AM

PHP 클라이언트 URL (CURL) 확장자는 개발자를위한 강력한 도구이며 원격 서버 및 REST API와의 원활한 상호 작용을 가능하게합니다. PHP CURL은 존경받는 다중 프로모토콜 파일 전송 라이브러리 인 Libcurl을 활용하여 효율적인 execu를 용이하게합니다.

Laravel 테스트에서 단순화 된 HTTP 응답 조롱Laravel 테스트에서 단순화 된 HTTP 응답 조롱Mar 12, 2025 pm 05:09 PM

Laravel은 간결한 HTTP 응답 시뮬레이션 구문을 제공하여 HTTP 상호 작용 테스트를 단순화합니다. 이 접근법은 테스트 시뮬레이션을보다 직관적으로 만들면서 코드 중복성을 크게 줄입니다. 기본 구현은 다양한 응답 유형 단축키를 제공합니다. Illuminate \ support \ Facades \ http를 사용하십시오. http :: 가짜 ([ 'google.com'=> ​​'Hello World', 'github.com'=> ​​[ 'foo'=> 'bar'], 'forge.laravel.com'=>

Codecanyon에서 12 개의 최고의 PHP 채팅 스크립트Codecanyon에서 12 개의 최고의 PHP 채팅 스크립트Mar 13, 2025 pm 12:08 PM

고객의 가장 긴급한 문제에 실시간 인스턴트 솔루션을 제공하고 싶습니까? 라이브 채팅을 통해 고객과 실시간 대화를 나누고 문제를 즉시 해결할 수 있습니다. 그것은 당신이 당신의 관습에 더 빠른 서비스를 제공 할 수 있도록합니다.

PHP에서 늦은 정적 결합의 개념을 설명하십시오.PHP에서 늦은 정적 결합의 개념을 설명하십시오.Mar 21, 2025 pm 01:33 PM

기사는 PHP 5.3에 도입 된 PHP의 LSB (Late STATIC BING)에 대해 논의하여 정적 방법의 런타임 해상도가보다 유연한 상속을 요구할 수있게한다. LSB의 실제 응용 프로그램 및 잠재적 성능

프레임 워크 사용자 정의/확장 : 사용자 정의 기능을 추가하는 방법.프레임 워크 사용자 정의/확장 : 사용자 정의 기능을 추가하는 방법.Mar 28, 2025 pm 05:12 PM

이 기사에서는 프레임 워크에 사용자 정의 기능 추가, 아키텍처 이해, 확장 지점 식별 및 통합 및 디버깅을위한 모범 사례에 중점을 둡니다.

See all articles

핫 AI 도구

Undresser.AI Undress

Undresser.AI Undress

사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover

AI Clothes Remover

사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool

Undress AI Tool

무료로 이미지를 벗다

Clothoff.io

Clothoff.io

AI 옷 제거제

AI Hentai Generator

AI Hentai Generator

AI Hentai를 무료로 생성하십시오.

뜨거운 도구

MinGW - Windows용 미니멀리스트 GNU

MinGW - Windows용 미니멀리스트 GNU

이 프로젝트는 osdn.net/projects/mingw로 마이그레이션되는 중입니다. 계속해서 그곳에서 우리를 팔로우할 수 있습니다. MinGW: GCC(GNU Compiler Collection)의 기본 Windows 포트로, 기본 Windows 애플리케이션을 구축하기 위한 무료 배포 가능 가져오기 라이브러리 및 헤더 파일로 C99 기능을 지원하는 MSVC 런타임에 대한 확장이 포함되어 있습니다. 모든 MinGW 소프트웨어는 64비트 Windows 플랫폼에서 실행될 수 있습니다.

SublimeText3 영어 버전

SublimeText3 영어 버전

권장 사항: Win 버전, 코드 프롬프트 지원!

에디트플러스 중국어 크랙 버전

에디트플러스 중국어 크랙 버전

작은 크기, 구문 강조, 코드 프롬프트 기능을 지원하지 않음

VSCode Windows 64비트 다운로드

VSCode Windows 64비트 다운로드

Microsoft에서 출시한 강력한 무료 IDE 편집기

ZendStudio 13.5.1 맥

ZendStudio 13.5.1 맥

강력한 PHP 통합 개발 환경