【发布时间】:2018-04-25 08:00:40
【问题描述】:
我有一个包含三列的数据库:idKernfragen;核心;吉比特
我想使用“Gebiet”中的选项设置一个下拉列表 - 这工作正常。我还设法从数据库中选择了所有信息。但是,我想使用下拉菜单中的选定选项作为变量,并将“WHERE”添加到我的 SQL 查询中,以便仅显示 where 'Gebiet'=Dropdown-Selection。
这是我的代码:
<?php
require_once ('config.php');
$db = mysqli_connect (
MYSQL_HOST,
MYSQL_BENUTZER,
MYSQL_KENNWORT,
MYSQL_DATENBANK
);
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
<div id="select">
<select name="gebiet1" onchange="this.form.submit();">
<?php
$gebietausgabe = mysqli_query($db, "SELECT DISTINCT Gebiet FROM kernfragen");
while ($row = $gebietausgabe->fetch_assoc())
{
echo "<option value=\"gebiet1\">" . $row['Gebiet'] . "</option>";
}
?>
</select>
</div>
</form>
<br>
<br>
<?php
$ergebnis = mysqli_query($db, "SELECT idKernfragen, Kernfrage FROM kernfragen");
while($row = mysqli_fetch_object($ergebnis))
{
echo $row->idKernfragen;
echo '.) ';
echo $row->Kernfrage;
print "<br>";
}
?>
非常感谢!
【问题讨论】:
-
在查询中使用
where gebiet = $_POST['gebiet1']
标签: php sql select where dropdown