PHP-从数据库获取值并将其设置为HTML select标记的值
希望有人可以帮助我。
用MySQL数据库为PHP的药草厂开发库存管理系统。我目前正在开发一个页面,用户可以在其中编辑包含草药的长凳之一的值。
Hope someone can help me out. Developing a stock management system for a herb factory in PHP with a MySQL database. I'm currently developing a page where the user can edit the value of one of the benches that holds the herbs.
我已经在替补席上绘制了详细信息,它们位于名为 $ bench_data
的数组中,该数组包含变量草药
,数量
,等等。
I've drawn in the benches details and they're in an array called $bench_data
which contains variable herb
, quantity
, etc.
我有一个html选择标签,用户可以在其中选择要生产的草药
I have a html select tag where the user selects the herb being produced
Herb*:<br>
<select name='herb' ">
<option value="default">-----</option>
<option value="basil">Basil</option>
<option value="coriander">Coriander</option>
<option value="parsley">Parsley</option>
<option value="mint">Mint</option>
<option value="rosemary">Rosemary</option>
<option value="thyme">Thyme</option>
</select>
我想做的是吃草药当用户进入页面时,所选标记中已经存在的选定工作台的值。
What I want to do is have the herb value of the selected bench already in the select tag when the user enters the page.
我设法用数量-价值PHP
I've managed to do it with quantity - 'the php in value'
Quanity<br>
<input type="text" name="quantity" value="<?php echo $bench_data['quantity']; ?>">
但是当有不同的选项
s
预先感谢
您可以使用 selected属性告诉浏览器页面加载时应显示哪个选项,例如,在每个选项上执行以下操作:
You use the "selected" attribute to tell the browser which option should be showing on page load. For example, on each option do it like this:
<option value="basil" <?php if ($bench_data['herb']=='basil'){echo 'selected';}?>>
Basil
</option>
在这里很有帮助链接