我真的很想知道set_select
中的codeigniter中的select字段。我已经尝试了很多方法,但它不起作用。
我在这里有一个变量$date_dossier = date_parse($patient['patient_date_dossier']);
,但它没有定义下面的函数:
<?php echo form_error('dossier_day') ?>
<?php
$option_day = array(
'01' => '01', '02' => '02', '03' => '03', '04' => '04', '05' => '05', '06' => '06', '07' => '07',
'08' => '08', '09' => '09', '10' => '10', '11' => '11', '12' => '12', '13' => '13', '14' => '14',
'15' => '15', '16' => '16', '17' => '17', '18' => '18', '19' => '19', '20' => '20', '21' => '21',
'22' => '22', '23' => '23', '24' => '24', '25' => '25', '26' => '26', '27' => '27',
'28' => '28', '29' => '29', '30' => '30', '31' => '31'
);
echo'<select name="dossier_day" class="form" id="day">';
for ($a = 1; $a <= 31; $a++) {
?>
<option value="<?php echo $a < 10 ? '0' . $a : $a ?>">
<?php if($a==$date_dossier['day']){
echo 'selected='.'"'.$a.'"';
}?>
<?php echo $a < 10 ? '0' . $a : $a ?></option>
<?php
}
echo'</select>'; echo '<span style="color:red">'.form_error('dossier_day').'</span>'
?>
答案 0 :(得分:0)
这样做:
echo form_error('dossier_day');
echo '<select name="dossier_day" class="form" id="day">';
foreach( range(1, 31) as $day ) {
// Convert in leading zero format for 01 to 09
$_day = sprintf("%02d", $day);
if( $_day == $date_dossier['day'] )
echo '<option selected="selected" value="'.$_day.'">'.$_day.'</option>';
else
echo '<option value="'.$_day.'">'.$_day.'</option>';
}
echo '</select>';
echo form_error('dossier_day', '<span style="color:red">', '</span>');
答案 1 :(得分:0)
<?php
echo form_error('dossier_day');
$option_day = array(
'01' => '01', '02' => '02', '03' => '03', '04' => '04', '05' => '05', '06' => '06', '07' => '07',
'08' => '08', '09' => '09', '10' => '10', '11' => '11', '12' => '12', '13' => '13', '14' => '14',
'15' => '15', '16' => '16', '17' => '17', '18' => '18', '19' => '19', '20' => '20', '21' => '21',
'22' => '22', '23' => '23', '24' => '24', '25' => '25', '26' => '26', '27' => '27',
'28' => '28', '29' => '29', '30' => '30', '31' => '31'
);
$d_dossier = $date_dossier['day'];
if (intval($d_dossier) < 10) $d_dossier = sprintf('%02d', $d_dossier);
$extra = array("class" => "form" "id" => "day");
echo form_dropdown('dossier_day', $options_day, $d_dossier, $extra);
echo '<span style="color:red">'.form_error('dossier_day').'</span>';
?>