How Smarty outputs multiple columns of multi-row data in a table

Source: Internet
Author: User
The code is as follows: Copy code

<Table border = "1">

<Tr>


<? Section name = site loop = $ siteList?>

 

<Td> <? $ SiteList [site]. url?> </Td>

 

<? If $ siteListColumn> 1?>

 

<? If $ smarty. section. site. index! = 0 & ($ smarty. section. site. index + 1) % $ siteListColumn = 0?>

</Tr>

<Tr>

<? /If?>

 

<? Else?>

</Tr>

<Tr>

<? /If?>

 

<? /Section?>

 

</Tr>

</Table>

The template delimiter in the example is <?>

The code is as follows: Copy code

<? Php

 

// Description: how Smarty outputs multiple columns and multiple rows of data in a table

 

// Set the list content

$ SiteList = array (

Array ('URL' => 'http: // www.111cn.net '),

Array ('URL' => 'http: // YITU.org '),

Array ('URL' => 'http: // www.111cn.net '),

Array ('URL' => 'http: // www.baidu.com '),

Array ('URL' => 'http: // www.yahoo.com.cn '),

Array ('URL' => 'http: // www.111cn.net '),

Array ('URL' => 'http: // www.sohu.com '),

Array ('URL' => 'http: // www.sina.com.cn '),

);

 

// List data statistics

$ SiteListCount = count ($ siteList );

 

// Display the number of columns

$ SiteListColumn = 3;

 

// If the list data cannot be filled with the last row,

// For example, there are 8 records in total, three records in each column, and one difference between the last row

If ($ siteListColumn> 1 & $ siteListCount % $ siteListColumn! = 0)

{

// Calculate the number of columns in the last row

$ EmptyColumn = $ siteListColumn-($ siteListCount % $ siteListColumn );

 

For ($ I = 0; $ I <$ emptyColumn; $ I ++)

{

// Fill with null values to ensure that the last row is correctly displayed

$ SiteList [$ siteListCount + $ I] = array ('URL' => '& nbsp ;');

}

}

 

// Assign the number of displayed columns to the template

$ Smarty-> assign ('sitelistcolumn ', $ siteListColumn );

 

// Assign values of the displayed data to the template

$ Smarty-> assign ('sitelist', $ siteList );

 

?>

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.