如何在每个选项标签中显示多个值?

时间:2017-02-22 06:08:09

标签: php mysql drop-down-menu html-select

我正在尝试在每个选项标签中显示多个值。我在这里阅读了一些问题并回答了我遇到的同样问题,例如this。但它并不适合我。选项标签的数据将使用mysql动态创建。

如何解决这个问题?提前谢谢!

E.g。

<option value="data 1,data 2, data 3....">Text 1</option>
<option value="data 6,data 7, data 8....">Text 2</option>

我目前的表格:

$results_streets = $wpdb->get_results('SELECT DISTINCT streets,stores FROM table WHERE streets IN ("Street 1") ORDER BY streets ASC', OBJECT);

<form action="" name="formName">
<div>
<select>
    <option name="default" class="filter_by" value="Select by Street">Select by Street</option>
    <?php
    foreach($results_streets as $option){
        if(isset($_POST['streets_list']) && $_POST['streets_list'] == $option->streets)
            echo '<option name="streets_list" class="filter_by" selected value="'. $option->stores .'">'. $option->streets .'</option>';
     };
    ?>
</select>
</div>
<input type="submit" value="Submit"/>
</form>

1 个答案:

答案 0 :(得分:0)

我认为选项标记的属性不是values。请改为value,如下所示:

<select name="test">
    <option value="data 1,data 2, data 3....">Text 1</option>
    <option value="data 6,data 7, data 8....">Text 2</option>
</select>

<强>更新

$results_streets = $wpdb->get_results('SELECT DISTINCT streets,stores FROM table WHERE streets IN ("Street 1") ORDER BY streets ASC', OBJECT);

<form action="" name="formName">
<div>
<select name='streets_list'>
    <option class="filter_by" value="Select by Street">Select by Street</option>
    <?php
    $values = "";
    foreach($results_streets as $option){
        if(isset($_POST['streets_list']) && $_POST['streets_list'] == $option->streets){
            $values.=$option->stores."|";
       } 
     }
    echo '<option class="filter_by" selected value="'. $values .'">Street 1</option>';
    ?>
</select>
</div>
<input type="submit" value="Submit"/>
</form>