douhui2307 2012-04-02 06:03
浏览 30
已采纳

为什么选择的选项不是第一位的

I have created a PHP code to echo the following div

<div id="main_catsel">
<select id="maincat" >

    <option value="1">none</option>
    <option value="2">Computer</option>
    <option value="4">Refrigerator</option>
    <option value="13" selected="selected" >Grinder</option>
    <option value="21">Bed</option>

</select>
</div>

I am using the option values and name as result from query . But now the default result still shown first is according to the id not according to selected="selected". Can any one sugsest a solution for this. Cant remove the id ,because its needed for insertion.

  $maincat .='<div class="main_catsel">';
     $sqlmaincat = $ilance->db->query("SELECT
            cid FROM " . DB_PREFIX . "seller_profile 
            WHERE userid = '" . $uid . "'");
    $row = $ilance->db->fetch_array($sqlmaincat);
    $sqlcat = $ilance->db->query("SELECT
            cid,title_spa 
            FROM " . DB_PREFIX . "categories 
            WHERE parentid = '0'
            ");
         if ($ilance->db->num_rows($sqlcat) > 0)
         {
          $maincat .='<h2><select id="maincat">';
           while ($rows = $ilance->db->fetch_array($sqlcat))
            {  
             if($rows['cid']==$row['cid'])
             {
              $maincat .='<option selected="selected" value="'.$rows['cid'].'">'.$rows['title_spa'].'</option>';
              }
              else
              {
                $maincat .='<option value="'.$rows['cid'].'">'.$rows['title_spa'].'</option>';
                }
             }  
                $maincat .='</select></h2>';
       }
        $maincat .='</div>';
  • 写回答

2条回答 默认 最新

  • doubang4881 2012-04-02 06:14
    关注

    What browser are you using?

    "On SGML and HTML" points out that some browsers only support the minimized form, i.e. selected rather than selected="selected".

    Or maybe you previously selected something, and your browser is remembering your choice. Try holding <kbd>Shift</kbd> and clicking the Reload button, or press <kbd>Ctrl</kbd>+<kbd>F5</kbd>.

    Or maybe the your browser is caching an older version of the page. Again Shift+Reload should help. Browser-specific details at Bypass your cache.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 CST仿真别人的模型结果仿真结果S参数完全不对
  • ¥15 请问在阿里云服务器中怎么利用数据库制作网站
  • ¥60 ESP32怎么烧录自启动程序
  • ¥50 html2canvas超出滚动条不显示
  • ¥15 java业务性能问题求解(sql,业务设计相关)
  • ¥15 52810 尾椎c三个a 写蓝牙地址
  • ¥15 elmos524.33 eeprom的读写问题
  • ¥15 用ADS设计一款的射频功率放大器
  • ¥15 怎么求交点连线的理论解?
  • ¥20 软件开发方法学习来了