How To Dropdown with search Php mysql

时间:2017-04-10 03:24:45

标签: php mysql

I want my dropdown list with search php with mysql. This is my code:

<td> Urgency (SLA)*</td>
<td> : </td>
<td>
    <select name="sla">
    <?php 
        $sla = $slas->get_sla();
        echo '<option value="'.$slaval['slaid'].'" selected="selected">'.$slaval['namasla'].'</option>';
        foreach ($sla as $slaval) 
        {   
            echo '<option value="'.$slaval['slaid'].'">'.$slaval['namasla'].'</option>';
        }
    ?>
    </select>

3 个答案:

答案 0 :(得分:0)

在foreach之前删除带有选项的第一个echo,在循环外部的$ slasval是未定义的。

<td> Urgency (SLA)*</td><td> : </td>
<td>
  <select name="sla">
    <?php 
        $sla = $slas->get_sla();
        foreach ($sla as $slaval) 
        {
            echo '<option value="'.$slaval['slaid'].'">'.$slaval['namasla'].'</option>';
        }
    ?>
    </select>
</td>

答案 1 :(得分:0)

&#13;
&#13;
<td> Urgency (SLA)*</td><td> : </td>
        <td><select name="sla">
            <?php 
                $sla = $slas->get_sla();
                foreach ($sla as $slaval) 
                {   echo '<option value="'.$slaval['slaid'].'">'.$slaval['namasla'].'</option>';
                }
            ?>
            </select>
&#13;
&#13;
&#13; 在第一个回显中,您会看到

的名称没有变量
$slaval

变量,该变量在foreach循环中可用。

答案 2 :(得分:-1)

尝试使用Datalist它可能会帮助您选择下拉列表

<td> Urgency (SLA)*</td><td> : </td>
<td><select name="sla" list="selectlist">
<datalist id='selectlist'>
<?php 
     $sla = $slas->get_sla();
     echo '<option value="'.$slaval['slaid'].'" selected="selected">'.$slaval['namasla'].'</option>';
     foreach ($sla as $slaval) 
     {
     echo '<option value="'.$slaval['slaid'].'">'.$slaval['namasla'].'</option>';
     }
?>