简体   繁体   English

在下拉列表中选择等于mysql输出的值

[英]Select the values in drop down that equals to mysql output

I have a multi dropdownbox thats generate the values from the msyqli output like Amsterdam, Rotterdam, Miami, New York...... 我有一个多下拉框,可以从msyqli输出生成值,例如阿姆斯特丹,鹿特丹,迈阿密,纽约...

I want to select the values whats equal to the values in $cats 我想选择等于$ cats中的值的值

So far its okay. 到目前为止还可以。

But the problem is the dropdown list have duplicated values. 但是问题是下拉列表的值重复。 Click here to show the problem How can I fix this problem? 单击此处显示问题如何解决此问题?

 $resultxx = mysqli_query($database->connection,"SELECT city FROM postcode
 GROUP BY city") or die(mysqli_error());


    $cats = explode(",", $ed['ophaal_locaties']);

    while($land = mysqli_fetch_array($resultxx)){
    $city = $land['city'];

     foreach($cats as $cat) {
    $cat = trim($cat);

     if($cat == $city){
    $sl = 'selected';
    }else{
    $sl = '';
    }

        echo "<option ".$sl.">".$city."</option>";
    }
 }

尝试使用以下SQL查询-

SELECT DISTINCT(city) FROM postcode

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM