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>
答案 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)
<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;
的名称没有变量
$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>';
}
?>