这是我试图填充CI的下拉列表(使用from helper):
foreach ($freetables as $t) :
$tableNo = $t['tableNo'];
$tableDescription = $t['description1'];
$data=array($tableNo=>$tableDescription1);
endforeach;
print_r($data);
//echo form_dropdown('table',$data,$this->session->userData('queueNo'));
echo form_dropdown('table',$data);
但是我只能看到下拉列表中的最后一项。
答案 0 :(得分:1)
每次迭代都会覆盖$data
数组,此处为:$data=array($tableNo=>$tableDescription1);
此解决方案假定tableno
是唯一的,值属性是tableno
,description1
作为相应选项。 (它避免了覆盖问题!)。
foreach ($freetables as $t)
{
$data[$t['tableNo']] = $t['description1'];
}
echo form_dropdown('table', $data);