ホームページ  >  記事  >  php教程  >  PHP と Smarty テンプレート テクノロジを使用して、静的ページをページングするためのコードを生成します。

PHP と Smarty テンプレート テクノロジを使用して、静的ページをページングするためのコードを生成します。

黄舟
黄舟オリジナル
2016-12-14 11:32:221243ブラウズ

lear_all_cache();//すべてのキャッシュをクリアします

//smarty.php
//smarty テンプレートを使用して HTML ファイルを作成します
//Rossy.cn@gmial.com
//2007-07-27 11:15

require_once("classes/Smarty. class.php"); //smarty文件
require_once("config.php"); //配置文件
require_once("mysql_class.php"); //データ库连接文件

$smarty = new Smarty();
$smarty->template_dir = "テンプレート";
$smarty->compile_dir ="templates_c";
$smarty->left_delimiter = "< {";
$smarty->right_delimiter ="}>";

$page_count = "3"; //一页の记录数
$Db = new Mysql;
$query = $Db->Query("Select * FROM Tablea orDER BYId DESC");
$tatol = $Db->FetchCount($query );
$pages = ceil($tatol / $page_count);
for ($j=1;$j<=$pages;$j++)
$showpages.="".$j."";

for ($i = 0;$i<$pages; $i++)
{
$start_page = $i *$page_count;   
if($pages>1)
{
$indexpath ="user_".($i+1).".htm";  //filename
$showpagestr= "第一页".$showpages." 最尾页";
}
else
{
$indexpath = "user.htm"; //ファイル名
$showpagestr= "";
}

$sql = "Select * FROM TableaorDER BY ID DESC LIMIT $start_page,$page_count";
$query =$Db->Query($sql) or die ("無効なクエリ");
if(($Db->FetchCount($query))<1){
$Admin ="數據庫沒有此數據";
}else{
while ($rs =$Db ->FetchArray($query)) {
$Admin[] =array('Id'=>$rs['Id'],'Name'=>$rs['Name'],'Nick'= >$rs['ユーザー名'],'タイプ'=>$rs['タイプ'],'メール'=>$rs['メール']);
}
}

$smarty-> assign(array('Site_Name'=>"系统",'AdminName'=>'ybfqlyq','AdminType'=>'Administrator','Type'=>'1'));
$smarty- >assign('Admin',$Admin);
$smarty->assign('Page_Str',$showpagestr);
$temp =$smarty->fetch('test.tpl', null, null, false );//模板文件
unset($Admin);
$showpagestr = "";
$fp=fopen($indexpath,'w');
fwrite($fp,$temp) ordie('作成に失敗しました') ;
}
$Db->Close();
echo "htm ファイルが正常に作成されました";
?>

test.tpl文件代码:


<{$SiteName}>
href="templates/css.css" type=text/cssrel= stylesheet>



  




        
       
       
Example of create html file usesmarty template with php

      cellSpacing=0 cellPadding=2 width="100%"align=center border=1>
       
       
        

        
        
        
        
       
       <{sectionname=adminlist loop=$Admin}>1">
          <{$Admin[adminlist].Id}>
          <{$Admin[adminlist].Name}>
          <{$Admin[adminlist].Nick}>
          <{$Admin[adminlist].Type}>
        

       
       <{/section}>
       
        
編號用戶名姓名類別郵件地址
href="mailto:<{$Admin[adminlist].Email}>"><{$Admin[adminlist].Email}>
<{$Page_Str}>

     
       


       Powered by www.ybfq.com     Rossy'sblog:http://www.ybfq.com/blog


     

$smartyArr = $smarty->get_template_vars();
// レコードの総数、表示各ページのレコード アイテム数、総ページ数
$pager_Total= count($smartyArr['productID']); =View";
// REQUEST から取得された現在のページのページ数$_GET[ 'pager_pageid']); ;
} elseif($ pager_pageid == $ pager_number && $ pager_number&gt; 1){"&lt;/a&gt; | nextページ"; $ pager_url。 >前のページ| 次のページ & lt;/a & gt; $ pager_links =" 前のページ | 次のページ ";

$ SMARTY-> assign('pager_EndNum',$pager_EndNum);
return$ Smarty->fetch("list.tpl");
?>







include "class/Smarty.class .php";
$tpl = new Smarty();
$tpl->config_dir = __SITE_ROOT . "/configs/";
$tpl->cache_dir = __SITE_ROOT . "/cache/";
$tpl-> ;left_delimiter = '<{';
$tpl- >right_delimiter = '}>';
?>



$page_count = " 3"; //ページごとのレコード数
$ tatol=$aa->selectpage("news","","");
$pages = ceil($tatol / $page_count);

if($tatol<2)
{
echo "ホーム/前のページ/次のページ/最後のページ";
}
if($tatol>2)
{
$p=2;
$e=0 ;
$name="ホームページ /前のページ / 次のページ/ 終了ページ & lt; /a & gt; ";

for ($ pi = 0; $ pi & lt; = $ tatol; $ pi ++) {
$ start_page = $ pi *$ page_count;

(($ pi+1) % $page_count==0)
{ $page_count";
// $query =$Db->Query($sql) または die("無効なクエリ");
$query=$aa->query($ sql) ordie("sql error") ;
//if(($Db->FetchCount($query))// $Admin = "データベースにはこのデータがありません";

/ / }else{

while ($rs = mysql_fetch_array( $query)) {
$Admin[] =array('Id'=>$rs['Id'],'title'=>$rs['title '],'content'=>$rs[ 'content']);
}
//}

$tpl->assign(array('Site_Name'=>"System",'AdminName'=>) ;'ybfqlyq','AdminType'=>'管理者','Type'=>'1'));
$tpl->assign('Admin',$Admin);
$tpl->assign ('Page_Str',$name);
$temp =$tpl->fetch('test.tpl', null, null, false);//テンプレート ファイル
unset($Admin);

///unset( $name);

// $showpagestr = "" ;
$fp=fopen("news".$p.".html",'w');
fwrite($fp,$temp) または die('create失敗しました');


$name="" ;
$name.="ホームページ / ";
$name.="前のページ / ";
$p++;

$p++;

if($p<>$pages+1)
{
$name.=" / ";
$name.="最後のページ";
else ️ $name.=" html>ホームページ / 前のページ/a> / 次のページ/ 最後のページ";

}

}


//これはもう 1 つの代コードを生成します
//for ($j=1;$j<=$pages;$j++)
// $showpages.= "".$j."";
//
//for ($i = 0;$i<$pages; $i++)
//{
// $start_page = $i *$page_count;    
// if($pages>1)
// {
// $indexpath ="user_".($i+1).".htm";  //ファイル名
// $showpagestr = "第一页".$showpages." 最尾页";
// }
// else
// {
// $indexpath = "user.htm"; //filename
// $showpagestr = "";
// }
//
// $sql ="Select * FROM news order BY ID DESC LIMIT$start_page,$page_count";
// // $query = $Db->Query($sql) or die("無効なクエリ");
// $query=$aa->query($sql) ordie("SQL エラー");
// //if( ($Db->FetchCount($query))//// $Admin = "數據庫沒有此數據";
//// }else{
// while ($rs = mysql_fetch_array( $query)) {
// $Admin[] =array('Id'=>$rs['Id'],'title'=>$rs['title'],'content'=>$ rs['content']);
// }
// //}
//
// $tpl->assign(array('Site_Name'=>"系统",'AdminName'=>' ybfqlyq','AdminType'=>'Administrator','Type'=>'1'));
// $tpl->assign('Admin',$Admin);
// $tpl-> ;assign('Page_Str',$showpagestr);
// $temp =$tpl->fetch('test.tpl', null, null, false);//模板文件
// unset($Admin);
// unset($showpagestr);
// $showpagestr = "";
// $fp=fopen($indexpath,'w');
// fwrite($fp,$temp) または die('create失敗しました');
//}
echo "htm ファイルを正常に作成しました";
?>

以上は PHP と Smarty 模板技術を利用して分页静态页面の代コードを生成する,希望可以帮助大家,更多相关内容请关注 PHP中文网(www.php.cn)

声明:
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。
前の記事:SQLSERVER カーソルおよびループ ステートメント次の記事:SQLSERVER カーソルおよびループ ステートメント

関連記事

続きを見る