$search_condition = "where name like '$foo%' ";
$sql = 'select contact_id, name, nick from contacts '.$search_condition.' order by name';
$smarty->assign('results', $db->getAssoc($sql) );
?>
The template which display "None found" if no results with {foreachelse}.
借助{foreachelse}标记在没有结果时模板输出"None found"字样。
{foreach key=cid item=con from=$results}
{$con.name} - {$con.nick}
{foreachelse}
No items were found in the search
{/foreach}
.index
index contains the current array index, starting with zero.
.index包含当前数组索引,从零开始。
Example 7-10. index example
例 7-10. index示例
{* The header block is output every five rows *}
{* 每五行输出一次头部区块 *}
{foreach from=$items key=myId item=i name=foo}
{if $smarty.foreach.foo.index % 5 == 0}
Title{/if}
{$i.label}{/foreach}
.iteration
iteration contains the current loop iteration and always starts at one, unlike index. It is incremented by one on each iteration.
iteration包含当前循环次数,与index不同,从1开始,每次循环增长1。
Example 7-11. iteration and index example
例 7-11. iteration和index示例
{* this will output 0|1, 1|2, 2|3, ... etc *}
{* 该例将输出0|1, 1|2, 2|3, ... 等等 *}
{foreach from=$myArray item=i name=foo}
{$smarty.foreach.foo.index}|{$smarty.foreach.foo.iteration},
{/foreach}
.first
first is TRUE if the current {foreach} iteration is the initial one.
first在当前{foreach}循环处于初始位置时值为TRUE。
Example 7-12. first property example
例 7-12. first属性示例
{* show LATEST on the first item, otherwise the id *}
{* 对于第一个条目显示LATEST而不是id *}
{foreach from=$items key=myId item=i name=foo}
{if $smarty.foreach.foo.first}LATEST{else}{$myId}{/if}{$i.label}{/foreach}
.last
last is set to TRUE if the current {foreach} iteration is the final one.
last在当前{foreach}循环处于最终位置是值为TRUE。
Example 7-13. last property example
例 7-13. last属性示例
{* Add horizontal rule at end of list *}
{* 在列表结束时增加一个水平标记 *})
{foreach from=$items key=part_id item=prod name=products}
{$prod}{if $smarty.foreach.products.last}
{else},{/if}
{foreachelse}
... content ...
{/foreach}
.show
show is used as a parameter to {foreach}. show is a boolean value. If FALSE, the {foreach}will not be displayed. If there is a {foreachelse} present, that will be alternately displayed.
show是{foreach}的参数. show是一个布尔值。如果值为FALSE,{foreach}将不被显示。如果有对应的{foreachelse},将被显示。
.total
total contains the number of iterations that this {foreach} will loop. This can be used inside or after the {foreach}.
total包括{foreach}将循环的次数,既可以在{foreach}中使用,也可以在之后使用。
Example 7-14. total property example
例 7-14. total属性示例
{* show rows returned at end *}
{* 在结束位置显示行数 *}
{foreach from=$items key=part_id item=prod name=foo}
{$prod.name>
{if $smarty.foreach.foo.last}
{/if}
{foreachelse}
... something else ...
{/foreach}
smarty -- foreach用法
{foreach},{foreachelse} 用于像访问序数数组一样访问关联数组 {foreach},{foreachelse} {foreach} is used to loop over an ...
smarty -- foreach用法详解
{foreach},{foreachelse} 用于像访问序数数组一样访问关联数组 {foreach},{foreachelse} {foreach} is used to loop over an ...
ecshop中foreach的详细用法归纳
ec模版中foreach的常见用法. foreach 语法: 假如后台:$smarty->assign('test',$test); {foreach from=$test item=list ...
PHP模板引擎Smarty内建函数section,sectionelse用法详解
本文实例讲述了PHP模板引擎Smarty内建函数section,sectionelse用法.分享给大家供大家参考,具体如下: section 是 Smarty 模板中除了 foreach 以外的另一种 ...
smarty foreach循环
1,smarty foreach1,单纯的数组array(1000,2000,3000),使用foreach(from = $array item=foo){$foo}2,键值对数组
(转)Smarty Foreach 使用说明
foreach 是除 section 之外处理循环的另一种方案(根据不同需要选择不同的方案). foreach 用于处理简单数组(数组中的元素的类型一致),它的格式比 section 简单许多,缺点是 ...
C# 和Java的foreach的不同用法
循环语句为苦逼的程序猿们提供了很大的便利,有while.do...while.for和 foreach.而且foreach语句很简洁,但是它的优点不仅仅在于此,它的效率也是最高的. 作为两个开发语言, ...
c#--foreach遍历的用法与split的用法
一. foreach循环用于列举出集合中所有的元素,foreach语句中的表达式由关键字in隔开的两个项组成.in右边的项是集合名,in左边的项是变量名,用来存放该集合中的每个元素. 该循环 ...
php foreach函数的用法
php foreach函数用法举例. Foreach 函数(PHP4/PHP5) foreach 语法结构提供了遍历数组的简单方式. foreach 仅能够应用于数组和对象,如果尝试应用于其他数据类 ...
随机推荐
HTTP Status
Web服务器响应浏览器或其他客户程序的请求时,其应答一般由以下几个部分组成:一个状态行,几个应答 头,一个空行,内容文档.下面是一个最简单的应答 : 状态行包含HTTP版本.状态代码.与状态代码对应的 ...
Ubuntu使用tcpdump工具
Ubuntu默认是安装好了tcpdump工具的,如果没有安装的话使用sudo apt-get install tcpdump即可安装. (如果遇到tcpdump: no suitable devi ...
代码坏味道特别篇————Long parameter List 过长的参数列表
刚开始学习编程时,老师说:讲方法所需要的东西都以参数的形式传入,那是我们好像还没学OO这个东东,要不就弄成全局变量,我擦,全局变量可牛逼了,刚开始学习的时候我们都在用全局变量,可是后来工作了,经理说不 ...
信号量的操作——semop函数
信号量的值与相应资源的使用情况有关,当它的值大于 0 时,表示当前可用的资源数的数量:当它的值小于 0 时,其绝对值表示等待使用该资源的进程个数.信号量的值仅能由 PV 操作来改变. 在 ...
apache开源项目--CouchDB
Apache CouchDB 是一个面向文档的数据库管理系统.它提供以 JSON 作为数据格式的 REST 接口来对其进行操作,并可以通过视图来操纵文档的组织和呈现. CouchDB 是 Apache ...
truncate 空间不释放问题
SQL> set linesize 200 SQL> select segment_name, sum(bytes / 1024 / 1024/1024) from dba_segment ...
MySQL mysqlimport 从txt文件中导入数据到mysql数据库
mysqlimport: 我说这个我们还是先从世界观方法论的高度来理解一下便有更加准确的把握.数据导入不外呼有两个部分 第一部分:目标对象--我们要把数据导给谁(mysqlimport 的目标对象自然 ...
grub 的安装与使用
安装与使用grub 要开始探究 GRUB 的精妙之处,首先需要下载.编译和安装它.但不要害怕 -- 根本不会修改您的引导记录 -- 我们只是要编译和安装 GRUB,就像其它程序一样,在此过程中我们可以 ...
哈密顿圈~Lingo程序
sets: c/1..15/:u; link(c,c):w,x; endsets data: w=@ole('第二题第一组.xls','d'); enddata n=@size(c); min=@su ...