dooo61733 2014-07-08 08:51
浏览 12

在下拉列表中只显示一次相同的项目?

I have the following drop down list, that has a common item 'a'. This item is shown two times in output, but it want to have it only once. Can anybody help me?

<select name="">
<option value="a">a</option>

<option value="a">a</option>
<option value="b">b</option>

 </select>

My code is

 <select name="brand" id="brand" class="txtfld" >
      <option value="">Select</option>
      <?php
           $country_sql="SELECT DISTINCT(brand) FROM customer where status='A' and brand<>''";
           $result_country=executequery($country_sql);

           while($country_array=ms_stripslashes(mysql_fetch_array($result_country)))
           {
                $sel_con=($country_array['brand']==$_REQUEST['brand'])? " selected='selected'" : " ";

                $brand=$country_array['brand'];
                $brand2=explode('|',$brand);
                if(count($brand2)<2)
                {
                     ?><option value="<?=$brand;?>" ><?=$brand;?></option><?php
                }
                else
                {
                     for($i=0;$i<count($brand2);$i++)
                     {
                          ?><option value="<?=$brand2[$i];?>" ><?=$brand2[$i];?></option><?php
                     }
                }
           }
      ?>
 </select>
  • 写回答

2条回答 默认 最新

  • duandangqin0559 2014-07-08 09:04
    关注

    You can use array_unique() which will keep only unique values of your array :

    $brand2 = explode('|',$brand);
    $brand2 = array_unique($brand2);
    
    评论

报告相同问题?

悬赏问题

  • ¥15 制裁名单20240508芯片厂商
  • ¥20 易康econgnition精度验证
  • ¥15 线程问题判断多次进入
  • ¥15 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接