我正在尝试编写循环以允许人们选择月份。但月份没有出现。
继承我的代码,它不起作用:
查看
<div>
<?php echo form_open("announcement/announcement_result");?>
<?php echo form_dropdown('q', $q, set_value('q'), 'id="q"'); ?>
<?php echo form_submit('search', 'SEARCH'); ?>
<?php echo form_close(); ?>
</div>
控制器
function announcement_list()
{
$q = '';
$data['q'] = $q;
$this->data['q'] = array(
'' => 'Month',
);
for($m = 1;$m <= 12; $m++)
{
$month = date("F", mktime(0, 0, 0, $m));
$this->data['q'][$month] = $month;
}
$data['results'] = $this->news_model->get_announcement_list($config['per_page'], $page);
}
答案 0 :(得分:0)
试试这个: 控制器
function announcement_list()
{
$q[]='';
for($m = 1;$m <= 12; $m++)
{
$month = date("F", mktime(0, 0, 0, $m));
$q[] = $month;
}
$data['q']=$q;
$data['results'] = $this->news_model->get_announcement_list($config['per_page'], $page);
}
答案 1 :(得分:0)
您要将值分配给$this->data
并尝试访问$q
。
这就是问题所在。
在控制器中更改如下
$q = '';
$data['q'] = $q;
$data['q'] = array(
'' => 'Month',
);
for ($m = 1; $m <= 12; $m++) {
$month = date("F", mktime(0, 0, 0, $m));
$data['q'][$month] = $month;
}