首页
开发手册
应用中心
工具
用户中心
Ease Template Cyclic Usage
English
中文简体
English
上一篇
下一篇
### Ease Template Cyclic Usage Every program involves loop data, but it is a more complicated and more complicated method. Introducing loop to template is a more distinctive feature of template engine. Ease Template In order to facilitate the application, an incremental variable will be added each time the loop$_i Ease Template analyzed the native two loops of php:foreach、while. #### foreach usage ``` equal foreach($user_list AS $user) ``` test_4.php ``` 'tonsen', 'pass' => '654321', ), array( 'name' => 'FoundPHP', 'pass' => '123456', ) ); $tpl->set_file('test_4'); $tpl->p(); ?> ``` view/test_4.htm ``` loop code: ID:{_i} account number:{user['name']} password:{user['pass']} Unable to get the loop data code: ID:{_i} account number:{users['name']} password:{users['pass']} method for judging and prompting detection$_i==0
Sorry, no loop data!
```
------------ #### while usage ``` equal while($user = $db->fetch_array($query)) ``` When we loop the database, we often use while to achieve higher efficiency. In order to be more efficient, ET introduces database objects into the template in the loop, saving a lot of conversion and loop times. test database content: ``` CREATE TABLE `users` ( `uid` INT( 3 ) NOT NULL AUTO_INCREMENT PRIMARY KEY , `username` VARCHAR( 64 ) NOT NULL , `password` VARCHAR( 32 ) NOT NULL ) TYPE = MyISAM ; INSERT INTO `users` (`uid`, `username`, `password`) VALUES (1, 'FoundPHP', '654321'), (2, 'Ease Template', '123456'); ``` We load a simple database class, connect to the local database, and connect to the test library table. test_5.php ``` '127.0.0.1', 'dbuser' => 'root', 'dbpass' => 'root', 'dbname' => 'FoundPHP', ); //connect to the database $db->DBLink($db_set); //index data $query = $db->query("SELECT * FROM users"); $tpl->set_file('test_5'); $tpl->p(); ?> ``` view/test_5.htm ``` loop code: ID:{_i} account number:{user['username']} password:{user['password']} Unable to get the loop data code: ID:{_i} account number:{users['username']} password:{users['password']} method for judging and prompting detection$_i==0
Sorry, no loop data!
```