2017-06-06 63 views
-1

即時嘗試創建更新表單。下面是我的製造年份和車輛狀態的HTML。更新值PHP

<div class="form-group"> 
<label class="control-label" >Year Manufactured:</label> 
<select class="form-control" name="yearManufactured" value="<?php if(isset($row['yearManufactured_vehicle'])) { echo $row['yearManufactured_vehicle']; } ?>"> 
    <option>Select</option> 
    <?php 
    foreach(range(1950, (int)date("Y")) as $year) { 
     echo "\t<option value='".$year."'>".$year."</option>\n\r"; 
    } 

    ?> 
    </select> 
</div> 

<div class="form-group"> 
<label>Vehicle Status</label> 
    <select class="form-control" name="yearManufactured" value="<?php if(isset($row['yearManufactured_vehicle'])) { echo $row['yearManufactured_vehicle']; } ?>"> 
<option>Select</option> 
    <?php 
    foreach(range(1950, (int)date("Y")) as $year) { 
     echo "\t<option value='".$year."'>".$year."</option>\n\r"; 
     if($row['yearManufactured']==$year){ 
     echo "selected"; 
     } 
    } 

    ?> 
</select> 
    </div> 

在車輛狀態中,我用來選擇確保插入數據的值以更新形式顯示。製造年份也是一樣嗎?我試圖把選擇內的選項字段,但它給了我錯誤。我如何使用製造年份內的選擇內部foreach?

+2

請包括錯誤 – Swellar

+0

,你可以直接呼應'selected',而不是關閉了'php',然後鍵入它 – Swellar

+0

@Swellar的我編輯的代碼,並把選擇的。仍然沒有變化。我如何解決這個問題? – yuki

回答

0

這解決了這個問題

<div class="form-group"> 
<label class="control-label" >Year Manufactured:</label> 
<select class="form-control" name="yearManufactured" value="<?php if(isset($row['yearManufactured_vehicle'])) { echo $row['yearManufactured_vehicle']; } ?>"> 
<option></option> 
<?php for ($x = 1950; $x <= date("Y"); $x++) { ?> 
    <option value="<?php echo $x; ?>"<?php if ($x==$row['yearManufactured_vehicle']){ ?> selected="selected"<?php } ?>><?php echo $x; ?></option> 
    <?php } ?> 
</select> 
</div>