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

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

WBOY
WBOYOriginal
2016-06-13 13:43:31775browse

急求: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>
Statement:
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