我需要帮助。我尝试做一些多选选项。我想获取下拉selected
值并将其传递给getprodi.php上的mysql查询
这是我到目前为止所写的内容..
的index.php
<select name="prodi" id="prodi">
<option> --- Pilih Prodi --- </option>
<option value="all"> --- SEMUA --- </option>
<?php
$pdo = new PDO('mysql:host=localhost;dbname=dataseminar', 'root', 'pwd');
#Set Error Mode to ERRMODE_EXCEPTION.
$pdo->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt = $pdo->prepare('SELECT * FROM prodi');
$stmt->execute();
while($row = $stmt->fetch(PDO::FETCH_ASSOC))
{
if($row['idprodi'] != "")
{
echo '<option value="'.$row['idprodi'].'">'.$row['namaprodi'].'</option>';
}
else
{
echo '<option value="all">--SEMUA--</option>';
}
}
?>
</select>
<div>
NIK :
<select name="nik" id="nik">
<option> --- Pilih NIK --- </option>
<option value="all"> --- SEMUA --- </option>
<?php
$pdo = new PDO('mysql:host=localhost;dbname=dataseminar', 'root', 'pwd');
#Set Error Mode to ERRMODE_EXCEPTION.
$pdo->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql = 'SELECT * FROM dosen ORDER BY nik';
$stmt = $pdo->prepare($sql);
$stmt->execute();
while($row = $stmt->fetch(PDO::FETCH_ASSOC))
{
if($row['nik'] != "")
{
echo '<option value="'.$row['nik'].'">'.$row['nik'].' - '.$row['namalengkapgelar'].'</option>';
}
}
?>
</select>
</div><br>
如您所见,选项值来自数据库
现在,某些部分来自getprodi.php
$prodi=$_POST['prodi']; //refer to selected value?
$nik=$_POST['nik'];
try{
$DB_con->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$show = $DB_con->query("SELECT s.nik, d.namalengkapgelar, p.namaprodi, s.namaseminar, s.tugas, s.tempat, s.waktu, s.sertifikat, d.idprodi
FROM seminar AS s LEFT JOIN dosen as d ON s.nik = d.nik
LEFT JOIN prodi as p ON d.idprodi = p.idprodi
WHERE s.waktu BETWEEN '$tgl_awal' AND '$tgl_akhir' AND d.idprodi = '$prodi'");
$show->execute();
if($prodi == 'all' && $nik == 'All' )
{//show data
}
else if ($prodi == 'all' && $nik =! 'All' )
{//show data
}
else if ($nik != 'All' && $prodi != 'all' )
{//show data
}
}catch (Exception $e)
{
echo $e->getMessage();
}
我在索引上提交按钮,如果点击它将显示来自getprodi.php的表格。直到我写这个问题,我仍然混淆如何将选定的值传递给mysql查询。请帮忙。
提前谢谢你。