検索
ホームページバックエンド開発PHPチュートリアルPHP+smarty ページング原理とページング コード共有

$ this->config_dir="smarty/smarty/config_file.class.php";
$this->caching=false;
$this->template_dir = "smarty/templates/";
    $this-> ache_dir = "smarty/smarty_cache/";
  1. $this->left_delimiter = "{";
  2. $this->right_delimiter = "}";
  3. }
  4. }
  5. ?>
  6. コード
  7. 2、adodb、接続データベース クラスをコピーします。
  8. class conndb
{
var $dbtype;var $host;var $user;
var $pwd;

var $dbname;

var $debug;//false はデバッグ情報を表示しません。それ以外の場合は、 , 表示
var $conn;
function __construct($dbtype,$host,$user,$pwd,$dbname,$debug=false)
    {
  1. $this->dbtype = $dbtype;
  2. $this->construct($dbtype,$host,$user,$pwd,$dbname,$debug=false) host = $host;
  3. $this->user = $user;
  4. $this->pwd = $pwd;
  5. $this->dbname = $dbname;
  6. $this->debug = $debug;
  7. }
  8. //データベース接続を実装し、接続オブジェクトを返します(個人的な理解ではadodbオブジェクトを返すと言えます)
  9. function getconnid()
  10. {
  11. include_once('adodb5/adodb.inc.php');
  12. if($ this->dbtype == "mysql" || $this->dbtype == "mssql")
  13. {
  14. if($this->dbtype == "mysql")
  15. {
  16. $this->conn = newadoconnection(" mysql");// adodb オブジェクトを作成し、データベース タイプを mysql として宣言します
  17. }
  18. else
  19. {
  20. $this->conn = newadoconnection("mssql");
  21. }
  22. $this->conn ->connect( $this->host,$this->user,$this->pwd,$this->dbname);
  23. }
  24. else if($this->dbtype == " access")
  25. {
  26. $this->conn = newadoconnection("access");
  27. $this->conn->connect("driver={microsoft access driver (*.mdb)};dbq=". $this->dbname.";uid=".$this->user.";pwd=".$this->pwd.";");
  28. }
  29. $this->conn-> ;execute("set names utf-8");
  30. if($this->dbtype == "mysql")
  31. {
  32. $this->conn->debug = $this->debug;
  33. }
  34. return $this ->conn;
  35. }
  36. function closeconnid()//データベースへの接続を閉じます
  37. {
  38. $this->conn->disconnection();
  39. }
  40. }
  41. Copyコード
  42. 3、データベース操作クラス:
  43. class admindb
{
var $sqlstr; var $conn; var $sqltype;
var $rs;

var $array;

function execsql($sqlstr,$conn)
{
$rs = $conn->execute($sqlstr);
    $sqltype = strto lower(substr(trim($sqlstr),0,6)); //strto lower() 関数は文字列を小文字に変換します。
  1. if($sqltype = "select")
  2. {
  3. $array = $rs->getrows(); // mysql_fetch_array 関数によって返される配列と同様
  4. if(count($array) == 0 || $ rs == false)
  5. {
  6. return false;
  7. }
  8. else
  9. {
  10. return $array;
  11. }
  12. }
  13. else if($sqltype = "update"||$sqltype = "insert"||$sqltype = " delete")
  14. {
  15. if($rs)
  16. {
  17. return true;
  18. }
  19. else
  20. {
  21. return false;
  22. }
  23. }
  24. }
  25. }
  26. コードをコピー
  27. 4、分页类:

    1. class seppage

    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->配列) == 0 || $this->rs == false)
    26. {
    27. return false;
    28. }
    29. else
    30. {
    31. return $this->array;
    32. }
    33. }
    34. 関数 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.="absolutepage()-1).$anothersearchstr." class=".$class.">上一页";
    53. }
    54. else
    55. {
    56. $str.="上一页";
    57. }
    58. $str.=" ";
    59. if(!$this->rs->atlastpage())

    60. {
    61. $str.="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("[font face=混体_gb2312]","",$content);
    19. $content=str_replace("[font face=混体_gb2312]","< ; font face=新宋体>",$content);
    20. $content=str_replace("[font face=公式スクリプト]","",$content);
    21. $content=str_replace (" [/font]","
    22. ",$content);
    23. //$content=str_replace(chr(32)," ",$content);
    24. $content=str_replace("[フォント サイズ=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("[font size=5]","",$content);
    29. $content=str_replace("[font size=6]", "",$content);
    30. $content=str_replace("[フィールドセット][凡例]","",$ content) ;

    31. $content=str_replace("[/legend]","",$content);
    32. $content=str_replace("[/fieldset]","",$ content) ;
    33. return $content;
    34. }
    35. }
    コードをコピー
    上記の 4 つのクラスをすべて 1 つのクラス ファイル system.class.inc.php.

    に配置します。

    さらにいくつかのファイル: 1.system.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. function unhtml($params)
    16. {
    17. extract($params);
    18. $text=$content;
    19. global $usefun;
    20. return $usefun->unhtml($text );
    21. }
    22. $smarty->register_function("unhtml","unhtml");

    23. ?>
    コードをコピーします

    2、実行文書、index.php:

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

    3、解析文件,index.html:

    1. 椤垫ā
    2. PHP+smarty ページング原理とページング コード共有
    3.  
      PHP+smarty ページング原理とページング コード共有
    4.  
    5. {if $isbbs=="t"}
    6.   
声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。
トラフィックの高いウェブサイトのPHPパフォーマンスチューニングトラフィックの高いウェブサイトのPHPパフォーマンスチューニングMay 14, 2025 am 12:13 AM

thesecrettokeepingaphp-poweredwebsterunningsmootlyunderheavyloadinvolvesseveralkeystrategies:1)emform opcodecoduceSciptionexecutiontime、2)aatabasequerycachingwithiThing withiThistolessendavasoload、

PHPでの依存関係注射:初心者向けのコード例PHPでの依存関係注射:初心者向けのコード例May 14, 2025 am 12:08 AM

コードをより明確かつ維持しやすくするため、依存関係が関心(DI)に注意する必要があります。 1)DIは、クラスを切り離すことにより、よりモジュール化されます。2)テストとコードの柔軟性の利便性を向上させ、3)DIコンテナを使用して複雑な依存関係を管理しますが、パフォーマンスの影響と円形の依存関係に注意してください。

PHPパフォーマンス:アプリケーションを最適化することは可能ですか?PHPパフォーマンス:アプリケーションを最適化することは可能ですか?May 14, 2025 am 12:04 AM

はい、最適化されたAphPossibleandessention.1)CachingingusapCutoredatedAtabaseload.2)最適化、効率的なQueries、およびConnectionPooling.3)EnhcodeCodewithBultinctions、Avoididingglobalbariables、およびUsingopcodeching

PHPパフォーマンスの最適化:究極のガイドPHPパフォーマンスの最適化:究極のガイドMay 14, 2025 am 12:02 AM

keyStrategIestsoSificlyvoostphpappliceperformanceare:1)useopcodecachinglikeToreexecutiontime、2)最適化abaseの相互作用とプロペラインデックス、3)3)構成

PHP依存性噴射コンテナ:クイックスタートPHP依存性噴射コンテナ:クイックスタートMay 13, 2025 am 12:11 AM

aphpDependencyInjectionContaineriSATOULTAINATINAGECLASSDEPTINCIES、強化測定性、テスト可能性、および維持可能性。

PHPの依存噴射対サービスロケーターPHPの依存噴射対サービスロケーターMay 13, 2025 am 12:10 AM

SELECT DEPENTENCINGINOFCENT(DI)大規模なアプリケーションの場合、ServicElocatorは小さなプロジェクトまたはプロトタイプに適しています。 1)DIは、コンストラクターインジェクションを通じてコードのテスト可能性とモジュール性を改善します。 2)ServiceLocatorは、センター登録を通じてサービスを取得します。これは便利ですが、コードカップリングの増加につながる可能性があります。

PHPパフォーマンス最適化戦略。PHPパフォーマンス最適化戦略。May 13, 2025 am 12:06 AM

phpapplicationscanbeoptimizedforspeedandEfficiencyby:1)enabingopcacheinphp.ini、2)PreparedStatementswithpordatabasequeriesを使用して、3)LoopswithArray_filterandarray_mapfordataprocessing、4)の構成ngincasaSearverseproxy、5)

PHPメールの検証:電子メールが正しく送信されるようにしますPHPメールの検証:電子メールが正しく送信されるようにしますMay 13, 2025 am 12:06 AM

PHPemailvalidationinvolvesthreesteps:1)Formatvalidationusingregularexpressionstochecktheemailformat;2)DNSvalidationtoensurethedomainhasavalidMXrecord;3)SMTPvalidation,themostthoroughmethod,whichchecksifthemailboxexistsbyconnectingtotheSMTPserver.Impl

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衣類リムーバー

Video Face Swap

Video Face Swap

完全無料の AI 顔交換ツールを使用して、あらゆるビデオの顔を簡単に交換できます。

ホットツール

SecLists

SecLists

SecLists は、セキュリティ テスターの究極の相棒です。これは、セキュリティ評価中に頻繁に使用されるさまざまな種類のリストを 1 か所にまとめたものです。 SecLists は、セキュリティ テスターが必要とする可能性のあるすべてのリストを便利に提供することで、セキュリティ テストをより効率的かつ生産的にするのに役立ちます。リストの種類には、ユーザー名、パスワード、URL、ファジング ペイロード、機密データ パターン、Web シェルなどが含まれます。テスターはこのリポジトリを新しいテスト マシンにプルするだけで、必要なあらゆる種類のリストにアクセスできるようになります。

SublimeText3 英語版

SublimeText3 英語版

推奨: Win バージョン、コードプロンプトをサポート!

SublimeText3 Linux 新バージョン

SublimeText3 Linux 新バージョン

SublimeText3 Linux 最新バージョン

VSCode Windows 64 ビットのダウンロード

VSCode Windows 64 ビットのダウンロード

Microsoft によって発売された無料で強力な IDE エディター

SublimeText3 Mac版

SublimeText3 Mac版

神レベルのコード編集ソフト(SublimeText3)