【问题标题】:option list using array - php [duplicate]使用数组的选项列表 - php [重复]
【发布时间】:2016-06-29 02:27:33
【问题描述】:

数据库中的数据已经正常。我的问题是,它在选项列表中没有出现,只是空白,但是当我将光标放在选项列表上时,它显示有数据

    <select style="width: 100px" id="txteventroomtype" onchange="selectfunctionroom(this.value);">
                   <?php
                $getroomtype = "select category from tblroomcat";
                $otherroomtyperesult = mysql_query($getroomtype);
                while($otherroomtype = mysql_fetch_array($otherroomtyperesult))
                { echo "<option value='" . $otherroomtype[0] . "'></option>"; }
            ?>
            </select>

【问题讨论】:

    标签: php arrays option


    【解决方案1】:

    请尝试以下代码

     <select style="width: 100px" id="txteventroomtype" onchange="selectfunctionroom(this.value);">
     <?php
                $getroomtype = "select category from tblroomcat";
                $otherroomtyperesult = mysql_query($getroomtype);
                while($otherroomtype = mysql_fetch_array($otherroomtyperesult))
                { echo "<option value='" . $otherroomtype[0] . "'>".$otherroomtype[0]."</option>"; }
    
     ?>
     </select>
    

    【讨论】:

      【解决方案2】:

      HTML &lt;option&gt; Tag

      因为你没有使用&lt;option&gt;???&lt;/option&gt;之间的数据

      示例:

      { echo "<option value='" . $otherroomtype[0] . "'>".$yourDBvalue."</option>"; }
      

      旁注:

      停止使用 mysql_* 扩展,它在 PHP 7 中已弃用并关闭,使用 mysqli_*PDO

      【讨论】:

        猜你喜欢
        • 2011-08-11
        • 2015-05-13
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-04-24
        相关资源
        最近更新 更多