thinkphp template cycle output volist Label Usage Example _php example

Source: Internet
Author: User
Tags php template smarty template

The example in this article describes the thinkphp template cyclic output volist label usage. Share to everyone for your reference, specific as follows:

The volist tag is used to iterate through a dataset or multidimensional array in a template.

Volist Label

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

<volist name= "list" id= "VO" >
username: {$vo [' username ']}<br/>
Email: {$vo [' email '
]}<br/> Registration time: {$vo [' regdate ']|date= ' y-m-d h:i ', ###}
</volist>

If you want to output multidimensional arrays, see the thinkphp template volist tags nested circular output multidimensional array method

Note: The Property value list (name= "list") of name cannot be changed arbitrarily, and needs to correspond to the template assignment instructions in the operation:

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

The ID represents a loop variable that can be specified arbitrarily, but not with the Name property.

Output part of the data

If you want to output part of the data in the result set, you need to specify the offset (data pointer) and length (data bar count) properties.

Output 5th to 14th record:

<volist name= "list" id= "Vo" offset= "5" length= ' >
username: {$vo [' username ']}<br/>
Email: {$vo ' Email ']}<br/>
registration time: {$vo [' regdate ']|date= ' y-m-d h:i ', ###}
 
 

Output odd/even record

The MoD parameter in Volist is equivalent to specifying a frequency, and the system will calculate the MoD parameter value (% operator in PHP) with the current actual record. In conjunction with a judgment label, such as an EQ label, you can control the output of data or data in a format that is displayed by frequency.

Example 1, outputting even records:

<volist name= "list" id= "Vo" mod= "2" >
<eq name= "mod" value= "0" >
username: {$vo [' username ']}<br] >
e-mail: {$vo [' email ']}<br/>
registration time: {$vo [' regdate ']|date= ' y-m-d h:i ', ###}
 
 

Example 2, an example of outputting all the records, but allowing the table to display a different background color interlaced:

<table>
<volist name= "list" id= "Vo" mod= "2" >
<tr<eq name= "mod" value= "0" > style= " Background-color: #FFF; " </eq>>
  <td> I'm cell content </td>
  <td> I'm also cell content </td>
</tr>
</ Volist>
</table>

Tip: The value of mod parameters can be set flexibly in actual use, not just parity.

Output loop variable

Specifies the number of variables for the key property to be used for the output loop (note that is not a datasheet primary key ID):

<volist name= "list" id= "Vo" key= "K" >
sequence  No.: {$k}<br/>
username: {$vo [' username ']}<br/>
e-mail: {$vo [' email ']}<br/>
registration time: {$vo [' regdate ']|date= ' y-m-d h:i ', ###}
 
 

Output array index

Use $key variables directly to output an array index:

<volist name= "list" id= "VO" >
array key:{$key}<br/>
username: {$vo [' username ']}<br/>
Email: {$ vo[' email ']}<br/>
registration time: {$vo [' regdate ']|date= ' y-m-d h:i ', ###}
 
 

Tips

Unlike the output loop variable, this key value is determined by the data itself, not by the volist loop output.

More interested in thinkphp related content readers can view the site topics: "thinkphp Introductory Course", "thinkphp Common Methods Summary", "Smarty Template Primer" and "PHP template technology Summary."

I hope this article will help you with the PHP program design based on thinkphp framework.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.