根据数据库中的值自动选择下拉列表

时间:2018-11-23 06:43:55

标签: php html

我在PHP页面中有一个非常简单的下拉菜单,如下所示。

<div class="form-group">
    <label class="col-md-3 control-label">FAQ Type :-</label>
    <div class="col-md-6">
        <select name="faq_type" id="faq_type" class="select2" required>
            <option value="0">Text</option>
            <option value="1">Image</option>
            <option value="2">Video</option>
        </select>
    </div>
</div>

我想根据从数据库中获取的值自动选择“文本”,“图像”或“视频”选择,对于其他字段,我可以像下面这样回显

<div class="col-md-6">
    <textarea name="question" id="question" rows="1" class="form-control" ><?php if(isset($_GET['faq_id'])){echo $row['question'];}?></textarea> 
</div>

如何对下拉菜单执行同样的操作?

编辑:根据回答,我可以做到,但是还有一个小问题,我只想设置if(isset($_GET['faq_id'])),否则要像现在显示的那样显示正常的所有按钮。

<div class="form-group">
    <label class="col-md-3 control-label">FAQ Type :-</label>
    <div class="col-md-6">
        <?php 
        if(isset($_GET['faq_id'])) {
            <select name="faq_type" id="faq_type" class="select2" required>
                <option value="0" <?php if($row['type'] == "0") echo "selected"; ?>>Text</option>
                <option value="1" <?php if($row['type'] == "1") echo "selected"; ?>>Image</option>
                <option value="2" <?php if($row['type'] == "2") echo "selected"; ?>>Video</option>
            </select>
        } else {

        }
        ?>      
    </div>
</div>

如果我喜欢这样,它会给我以下错误

Parse error: syntax error, unexpected '<' in C:\xampp\htdocs\new\add_faq.php on line 169

谢谢

1 个答案:

答案 0 :(得分:0)

对于下拉菜单,您可以这样设置所选字段

You have to first move to the element where you want to perform the context click
from selenium.webdriver import ActionChains 
from selenium.webdriver.common.keys import Keys
from selenium import webdriver
driver.get(url)

    # get the image source
img = driver.find_element_by_xpath('//img')
actionChains = ActionChains(driver)
actionChains.move_to_element(img).context_click().send_keys(Keys.ARROW_DOWN).send_keys(Keys.ARROW_DOWN).send_keys(Keys.RETURN).perform()