我无法将所选值传递到列表页面。当我选择一个选项并单击搜索时,默认值将传递到列表页面。 (默认值:最后添加的值)
$sql = mysqli_query($con, "select * from jobregestation order by id");
while ($row = $sql->fetch_assoc()) {
$id = $row['id'];
$name = $row['JobName'];
echo "<option value=" . $id . ">" . $name . "</option>";
}
提前致谢。
答案 0 :(得分:0)
你期待这样的事吗?
<?php
if(isset($_POST['submit'])){ // worked when click on serarch button
echo $_POST['exampleName'];
}
?>
<form action="" method='post'>
<select name="exampleName">
<?php
$sql = mysqli_query($con, "select * from jobregestation order by id");
while ($row = $sql->fetch_assoc()) {
$id = $row['id'];
$name = $row['JobName'];
echo "<option value=" . $id . ">" . $name . "</option>";
}
?>
</select>
<input type="submit" name="submit" value="Search"/>
</form>
答案 1 :(得分:0)
<select>
<?php
foreach ($sql->fetch_assoc() as $key=>$value)
{
echo "<option value = " .$value['id'] . ">" .$value['Jobname]."</option>";
}
?>
</select>
这应该有用。