thinkphp template loop output volist Label Usage Example _php instance

Source: Internet
Author: User
Tags php template
This article describes the thinkphp template looping output volist label usage. Share to everyone for your reference, as follows:

The Volist label is used to loop the output dataset or multidimensional array in the template.

Volist Label

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

 
  
   
  User name: {$vo [' username ']}
  
   
E-mail: {$vo [' email ']}
Registration time: {$vo [' regdate ']|date= "y-m-d h:i", # # #}

If you want to output a multidimensional array, see the thinkphp template volist label nested loop output multidimensional Array method

Note: The property value of Name list (name= "list") cannot be changed arbitrarily, it needs to correspond with the template assignment instruction in the operation:

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

The ID represents a looping variable, which can be arbitrarily specified, but must not conflict with the Name property.

Output partial data

If you want to output part of the data in the result set, you need to specify the offset (data pointer) with the length (number of data data bars) property.

Output 5th to 14th record:

 
  
   
  User name: {$vo [' username ']}
  
   
E-mail: {$vo [' email ']}
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 current actual record for the MoD parameter value (% operator in PHP). In conjunction with a judgment label (such as an EQ tag), the output data or data display format can be controlled according to the frequency.

Example 1, output even record:

 
  
  
   
    
   User name: {$vo [' username ']}
   
    
E-mail: {$vo [' email ']}
Registration time: {$vo [' regdate ']|date= "y-m-d h:i", # # #}

Example 2, the output of all records, but let the table interlaced display different background color example:

 
  
   
  <>
   
    
    Style= "Background-color: #FFF;" >  
  
    
 
    
   
  
 
  
  
I am a cell content I am also a cell content

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

Output loop variable

Specifies the number of times the key property is used to output the loop (note that it is not a data table primary key ID):

 
  
   
  Sequence  number: {$k}
  
   
User name: {$vo [' username ']}
E-mail: {$vo [' email ']}
Registration time: {$vo [' regdate ']|date= "y-m-d h:i", # # #}

Output array index

Use $key variables directly for the output array index:

 
  
   
  Array key:{$key}
  
   
User name: {$vo [' username ']}
E-mail: {$vo [' email ']}
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 this site topic: "thinkphp Introductory Tutorial", "thinkphp Common Methods Summary", "Smarty Template Primer Basic Tutorial" and "PHP template technology Summary."

It is hoped that this article is helpful to 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.