简体   繁体   English

将从数据库中获取的值分配给<select>使用PHP

[英]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.

相关问题 如何将从数据库获取的选项添加到 select php 的末尾 - How to add option fetched from the database to the end in select php 脚本仅返回从php数据库中获取的第一个值的ID - Script only returns the id of first value fetched from database in php 如何仅使用php来放大从数据库获取的图像的大小 - how to enlarge the size of an image fetched from database using only php 使用PHP格式化从数据库获取的大文本 - Formating a Large Text fetched from Database Using PHP 使用PHP创建JSON对象 - 来自数据库列的获取值 - JSON object creation using PHP - from fetched values of database columns 使用PHP从MySQL数据库中获取数据时不显示数据 - Data not displayed when fetched from a MySQL database using PHP 如何使用 JAVASCRIPT 从 Input 标签中获取值,输入标签的值是使用 php 从 mysql 数据库中获取的 - How to get values from Input tag using JAVASCRIPT ,the value of the input tags are fetched from mysql database using php 无法使用数据库中的 php 创建获取数据的 href 链接 - can not create href link of fetched data using php from database 如何显示使用JSON和PHP从数据库中获取的特定数据 - How to display specific data fetched from database using json with PHP 如何对使用PHP从MySQL数据库获取的记录进行排序? - How to do sorting of records fetched from MySQL database using PHP?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM