ThinkPHP templates do not contain loops.

Source: Internet
Author: User

Here, we should note that the methods for returning a single result include find, getBy, and so on. The following is a demonstration result based on an official example.
Looping array structure

The code is as follows: Copy code

Array (2 ){
[0] => array (8 ){
["Id"] => string (2) "33 & Prime;
["Title"] => string (6) "222111 & Prime;
["Content"] => string (6) "222111 & Prime;
["User_id"] => string (1) "0 & Prime;
["Create_time"] => string (10) "1342800330 & Prime;
["Update_time"] => string (1) "0 & Prime;
["Status"] => string (1) "1 & Prime;
["Email"] => string (12) "222111@1.com"
}
[1] => array (8 ){
["Id"] => string (2) "32 & Prime;
["Title"] => string (6) "654364 & Prime;
["Content"] => string (5) "adlkf"
["User_id"] => string (1) "0 & Prime;
["Create_time"] => string (10) "1342800285 & Prime;
["Update_time"] => string (1) "0 & Prime;
["Status"] => string (1) "1 & Prime;
["Email"] => string (9) "222@1.com"
}
}
One-dimensional arrays that cannot be recycled
Array (8 ){
["Id"] => string (2) "10 & Prime;
["Title"] => string (1) "6 & Prime;
["Content"] => string (1) "6 & Prime;
["User_id"] => string (1) "0 & Prime;
["Create_time"] => string (10) "1342627991 & Prime;
["Update_time"] => string (1) "0 & Prime;
["Status"] => string (1) "1 & Prime;
["Email"] => string (7) "1@1.com"
}


Postscript
Date: 2012-Oct-9th
If you want to convert a variable to ThinkPHP cyclically,
In terms of principle,
You only need to convert a one-dimensional array into a two-dimensional array,
Below are some simple steps

The code is as follows: Copy code

<? Php
// Suppose we have a one-dimensional array variable $ unloop
// Convert $ unloop to a two-dimensional array
$ Enloop = array ();
$ Enloop [0] = $ unloop;
// $ Enloop is an array that can be recycled by ThinkPHP.
?>

Foreach label
The foreach tag does not have as many functions as the volist tag. The advantage is that it can traverse and output objects, while the volist tag is usually used to output arrays.

Example:

The code is as follows: Copy code

<Foreach name = "list" id = "vo">
User Name: {$ vo. username} <br/>
Email: {$ vo. email} <br/>
Registration time: {$ vo. regdate | date = "Y-m-d H: I ",###}
<Hr/>
</Foreach>

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.