[英]Assigning Fetched value from database to <select> using PHP
I am fetching data from database using this query for an update form我正在使用此查询获取数据库更新表格中的数据
$vehicleQuery = "SELECT * FROM vehicle_purchased vp where vp.vehicle_id = ".$veh_id;
$vehicle = $db->query($vehicleQuery);
$vehicle_inv = $db->fetch_assoc($vehicle);`
Then, I have to bind values,but the technique I am using is not working on select, which is:然后,我必须绑定值,但是我使用的技术不适用于select,即:
<select class="custom-select form-control"
id="numberPlateType" name="numberPlateType"
value="<?php echo remove_junk($vehicle_inv['number_plate_desc']);?>">
<option value="1" selected>Both Original</option>
<option value="2">One Original, One Duplicate</option>
<option value="3">Both Duplicate</option>
</select>
So how can I do this?那我该怎么做呢?
( for example, $vehicle_inv['number_plate_desc'] = 2
then It should select "One Original, One Duplicate" but it keeps showing default value. (例如,
$vehicle_inv['number_plate_desc'] = 2
,则应选择“一个原稿,一个副本”,但它会一直显示默认值。
I am fetching data from database using this query for an update form我正在使用此查询获取数据库更新表格中的数据
$vehicleQuery = "SELECT * FROM vehicle_purchased vp where vp.vehicle_id = ".$veh_id;
$vehicle = $db->query($vehicleQuery);
$vehicle_inv = $db->fetch_assoc($vehicle);`
Then, I have to bind values,but the technique I am using is not working on select, which is:然后,我必须绑定值,但是我使用的技术不适用于select,即:
<select class="custom-select form-control"
id="numberPlateType" name="numberPlateType"
value="<?php echo remove_junk($vehicle_inv['number_plate_desc']);?>">
<option value="1" selected>Both Original</option>
<option value="2">One Original, One Duplicate</option>
<option value="3">Both Duplicate</option>
</select>
So how can I do this?那我该怎么做呢?
( for example, $vehicle_inv['number_plate_desc'] = 2
then It should select "One Original, One Duplicate" but it keeps showing default value. (例如,
$vehicle_inv['number_plate_desc'] = 2
,则应选择“一个原稿,一个副本”,但它会一直显示默认值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.