2015-04-25 108 views
0

我真的想知道set_select代碼選擇字段。我已經嘗試了很多方法,但不起作用。set_value代碼選擇字段選項

我有一個變量這裏$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
<?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>'; 

?> 
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>');