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

如何解决?提前致谢!

例如。

<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>

最佳答案

我认为选项标签的属性不是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>

09-12 14:49