<? 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 ); ?> |