我用smarty的另外的不用counter的方式,具体方法等会儿说

*.tpl
<table width="511" height="365" border="0" align="center" cellpadding="0" cellspacing="0" background="pic/bg1.gif">
{*assign var="bottomtitlenum" value="2"*}
{*section name=bst loop=$bottomshortcuttitle*}
 {*if ($smarty.section.bst.index mod $bottomtitlenum) eq 0 *}
 <tr valign="top">
 {*/if*}
 <td width="249" height="79">
 <table width="220" height="29" border="0" cellpadding="0" cellspacing="0">
 <tr>
 <td width="21" height="29">
 <div align="center"></div></td>
 <td width="199" align="left" valign="bottom">
 <TABLE width="110" height="21" border=0 cellPadding=0 cellSpacing=0>
 <TR>
 <TD width=3 background=中国UI设计网.files/k_t_bg2.gif height=21>
 <IMG height=21 src="pic/k_t2.gif" width=3></TD>
 <TD width=137 height=21 valign="middle" background=pic/k_t_bg2.gif>
 <DIV class=cn_12px_blue5_v18 align=center>{**title**}{*$bottomshortcuttitle[bst].bsctname *} </DIV></TD>
 <TD align=right width=3 background=中国UI设计网.files/k_t_bg.gif height=21>
 <IMG height=21 src="pic/k_t_r2.gif"width=3></TD>
 </TR>
 </TABLE>
 </td>
 </tr>
 </table>
 {**title end**}
 {**sub b start**}
 <table width="245" height="46" border="0" align="left" cellpadding="0" cellspacing="0">
 {*assign var="bottomcontentnum" value="3"*}
 {**内容循环**}
 {*section name=bsc loop=$bottomshortcutcontent[bst]*}
  {*if ($smarty.section.bsc.index mod $bottomcontentnum) eq 0 *}
  <tr>
  {*/if*}
 <td width="84" height="16" align="center" valign="middle">
 <a href="html/introduce.php">{*$bottomshortcutcontent[bst][bsc].bscname *}</a> </div></td>
  {*if ($smarty.section.bsc.index mod $bottomcontentnum) eq ($bottomcontentnum-1)*}
  </tr>
  {*/if*}
 {*/section*}
 </table> 
 {**sub  end**}
 </td>
 {*if ($smarty.section.bst.index mod $bottomtitlenum) eq ($bottomtitlenum-1) *}
 </tr>
 {*/if*}
{*/section*}
</table>          
*.php
<?php

 /*********************************************
   *
   *FileName: bottomshortcut.php
   *Author: W01F_dawn
   * Email: dlm364@sohu.com
   *
  *********************************************/
//包含相关文件
 
   require_once('./libs/Smarty.class.php');//类文件
   require_once('./include/db.php');//数据库文件

  
//本机的数据库相关数据
 
   $DBServer='localhost';
   $DBUser='root';
   $DBName='ccst';
   $DBPasswd='zzzzzz';
  
  
  
//建立smarty实例对象$smarty

   $smarty = new Smarty(); 
   $smarty->template_dir="./templates/default";
   $smarty->compile_check = true;
   $smarty->left_delimiter = "{*";
   $smarty->right_delimiter = "*}";

 
//    建立OakDB对象 $dbh 用来查询数据库,给定四个参数自动连接数据库

 
//  connect    the   database  
    $dbh_title = new OakDB($DBServer, $DBUser, $DBPasswd, $DBName);
//  query leftshortcuttitle ,return titles 
 $querytext_title='SELECT *  FROM  bottomshortcuttitle ' ;
    $dbrs_title=$dbh_title->queryDB($querytext_title);
 while ($asgnrs_title= mysql_fetch_array($dbrs_title))
    {
     $value_title [] = $asgnrs_title;
  //  connect    the   database  
  $dbh_content = new OakDB($DBServer, $DBUser, $DBPasswd, $DBName); 
  $querytext_content='SELECT *  FROM  bottomshortcut WHERE bsctitle=/''.$asgnrs_title['bsctname'].'/'' ;   
  $dbrs_content=$dbh_content->queryDB($querytext_content);//行指针dbrs
  
 //将数据库内容放入$value[]数组中
    while ($asgnrs_content = mysql_fetch_assoc($dbrs_content))
  {
   $value_temp [] = $asgnrs_content;
   echo 1;
  }
  $value_content [] = $value_temp ;
 }
 $smarty->assign('bottomshortcuttitle' ,$value_title);
 

 
//模板变量替换的内容 放到navigation.tpl 的section中
    $smarty->assign('bottomshortcutcontent' ,$value_content);


//编译并显示位于./templates下的navigation.tpl模板

   $smarty->display('bt.tpl');

?>

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值