Home > Backend Development > PHP Tutorial > ThinkPHP template loop output Volist tag usage example detailed explanation, thinkphpvolist_PHP tutorial

ThinkPHP template loop output Volist tag usage example detailed explanation, thinkphpvolist_PHP tutorial

WBOY
Release: 2016-07-12 08:56:18
Original
1022 people have browsed it

Detailed explanation of usage examples of Volist tags in ThinkPHP template loop output, thinkphpvolist

This article describes the usage of Volist tags in ThinkPHP template loop output. Share it with everyone for your reference, the details are as follows:

The

volist tag is used to loop through output data sets or multi-dimensional arrays in templates.

volist tag

In module operation, the select() method returns a two-dimensional array, which can be output directly using volist:

<volist name="list" id="vo">
用 户 名:{$vo['username']}<br />
电子邮件:{$vo['email']}<br />
注册时间:{$vo['regdate']|date="Y-m-d H:i",###}
</volist>

Copy after login

If you want to output a multi-dimensional array, please refer to "ThinkPHP template Volist tag nested loop output multi-dimensional array method"

Note: The attribute value list of name (name="list") cannot be changed at will and needs to correspond to the template assignment instruction in the operation:

$this->assign( "list", $list );

Copy after login

id represents a loop variable, which can be specified at will, but must not conflict with the name attribute.

Output some data

If you want to output part of the data in the result set, you need to specify the offset (data pointer) and length (number of data items) attributes.

Output records 5~14:

<volist name="list" id="vo" offset="5" length='10'>
用 户 名:{$vo['username']}<br />
电子邮件:{$vo['email']}<br />
注册时间:{$vo['regdate']|date="Y-m-d H:i",###}
<hr />
</volist>

Copy after login

Output odd/even records

The mod parameter in volist is equivalent to specifying a frequency, and the system will calculate the remainder (% operator in PHP) of the mod parameter value based on the current actual record. With the judgment tag (such as eq tag), the output data or data display format can be controlled according to the frequency.

Example 1, output even-numbered records:

<volist name="list" id="vo" mod="2">
<eq name="mod" value="0">
用 户 名:{$vo['username']}<br />
电子邮件:{$vo['email']}<br />
注册时间:{$vo['regdate']|date="Y-m-d H:i",###}
<hr />
</eq>
</volist>

Copy after login

Example 2, output all records, but let the table display different background colors in alternate rows:

<table>
<volist name="list" id="vo" mod="2">
<tr<eq name="mod" value="0"> style="background-color:#FFF;"</eq>>
  <td>我是单元格内容</td>
  <td>我也是单元格内容</td>
</tr>
</volist>
</table>

Copy after login

Tip: In actual use, the value of the mod parameter can be set flexibly, not just odd and even.

Output loop variable

Specify the key attribute to output the variable number of loops (note that it is not the primary key id of the data table):

<volist name="list" id="vo" key="k">
序  号:{$k}<br />
用 户 名:{$vo['username']}<br />
电子邮件:{$vo['email']}<br />
注册时间:{$vo['regdate']|date="Y-m-d H:i",###}
<hr />
</volist>

Copy after login

Output array index

Use the $key variable directly to output the array index:

<volist name="list" id="vo">
数组key:{$key}<br />
用 户 名:{$vo['username']}<br />
电子邮件:{$vo['email']}<br />
注册时间:{$vo['regdate']|date="Y-m-d H:i",###}
<hr />
</volist>

Copy after login

Tips

Different from the output loop variable, this key value depends on the data itself, rather than the volist loop output.

Readers who are interested in more thinkPHP-related content can check out the special topics on this site: "ThinkPHP Getting Started Tutorial", "ThinkPHP Common Methods Summary", "Smarty Template Basic Tutorial" and "PHP Template Technology Summary".

I hope this article will be helpful to everyone’s PHP programming based on the ThinkPHP framework.

Articles you may be interested in:

  • ThinkPHP template Volist tag nested loop output multi-dimensional array method
  • Solution to the line break bug of certain records controlled by the volist tag mod in Thinkphp
  • Tutorial on using volist tag nested loops in Thinkphp
  • Introduction to the usage of volist tag in Thinkphp
  • Difference and comparative example analysis of Thinkphp template tags if and eq
  • How thinkphp uses literal to prevent template tags from being parsed
  • Detailed explanation of the usage of In tag and Range tag of ThinkPHP template range judgment output
  • Detailed explanation of usage of Empty tag of ThinkPHP template judgment output
  • ThinkPHP template judgment output Detailed explanation of the usage of the Defined tag
  • ThinkPHP template judgment output Detailed explanation of the usage of the Present tag
  • Detailed explanation of the usage of the ThinkPHP template comparison tag
  • ThinkPHP template Switch tag usage example
  • How to use ThinkPHP template custom tags
  • How to use thinkPHP’s Html template tags

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1113704.htmlTechArticleDetailed explanation of the usage example of Volist tag output by ThinkPHP template loop, thinkphpvolist This article explains the usage of Volist tag loop output by ThinkPHP template. Share it with everyone for your reference, specifically...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template