Home > Backend Development > PHP Tutorial > 急求:thinkPHP中用循环赋值的有关问题(不需要连接数据库)

急求:thinkPHP中用循环赋值的有关问题(不需要连接数据库)

WBOY
Release: 2016-06-13 09:59:49
Original
913 people have browsed it

急求:thinkPHP中用循环赋值的问题(不需要连接数据库)
大家好,我是个thinkPHP新手:

我想将模板页面的一个控件里面的子项循环赋值,做成一个连续年份的下拉菜单,比如:从1988-2005年,应该怎样使用循环,谢谢!

------解决方案--------------------

PHP code
//在action中$fromYear = "2010";       //起始年$toYear = date("Y");      //结束年$listYear = array();while( $toYear >= $fromYear ){    $listYear[$fromYear] = $fromYear;    ++$fromYear;}$this->assign("listYear",$listYear);$this->assign("selectYear",array($toYear));/模板中选择年:   <div style="margin-left:10px;margin-bottom:10px;">   <taglib name="html"></taglib>   <select options="listYear" selected id="Year" name="Year"></select>    年</div><div class="clear">
                 
              
              
        
            </div>
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template