重新加载表单时,我无法显示数据列表中的所选选项。
echo '<input list="clients" name="client"><datalist id="clients"
name="client" value="'.$_POST['client'].'">';
while($row=mysqli_fetch_array($result))
{
if(isset($_POST['client']))
{
echo'<option value="'.$_POST['client'].'">';
}
else
{
echo'<option value="'.$row['partyname'].'">';
}
echo '</datalist>';
}
答案 0 :(得分:0)
尝试一下我能理解的:
<form method="post">
<?php
$con = mysqli_connect('localhost','root','','test');
$sql = 'select * from person';
$result = mysqli_query($con,$sql);
echo '<input list="clients" name="client">
<datalist id="clients" name="client" value="'.$_POST['client'].'">';
if(isset($_POST['client']))
{
echo'<option value="'.$_POST['client'].'">';
}
else
{
while($row=mysqli_fetch_array($result))
{
echo'<option value="'.$row['nameOfPerson'].'">';
}
}
echo '</datalist>';
?>
<br /><input type="submit" value="submit" name='submit'/>
</form>
未设置发布变量时的输出1
在输出2中,由于我尚未在数据库中插入新值,因此未显示先前的其余详细信息,我只是将新提交的值放入数据列表so if block executed
希望我能正确回答您的问题