我需要一些帮助。我在下面有一些代码,我的问题是,如何在选中时检索每个组合值?我真的很困惑。任何帮助将不胜感激,非常感谢。
这是第一个组合框
<div class="select-form">
<form action="#" method="POST">
<label>Tipe</label> <select name="tipeku">
<?php
echo "<option value=0 selected>- Pilih Tipe -</option>";
$tipe=mysql_query("SELECT * FROM tipe ORDER BY id_tipe ASC");
while($tipeb=mysql_fetch_array($tipe)){
echo "<option value=$tipeb[nama_tipe]>$tipeb[nama_tipe]</option>";
}?>
</select>
</form>
这是第二个组合框
<form class="clearfix" action="#" method="POST">
<label>Jenis</label>
<select name="jenisku">
<?php
echo "<option value=0 selected>- Pilih Jenis -</option>";
$jenis=mysql_query("SELECT * FROM jenis ORDER BY id_jenis ASC");
while($jenisb=mysql_fetch_array($jenis)){
echo "<option value=$jenisb[nama_jenis]>$jenisb[nama_jenis]</option>";
}?>
</select>
</form>
这是第3个组合框
<form class="clearfix" action="#" method="POST">
<label>Merk</label>
<select name="merkku">
<?php
echo "<option value=0 selected>- Pilih Merk -</option>";
$merk=mysql_query("SELECT * FROM kategori ORDER BY id_kategori ASC");
while($katb=mysql_fetch_array($merk)){
echo "<option value=$katb[nama_kategori]>$katb[nama_kategori]</option>";
}?>
</select>
</form>
这是第4个组合框
<form class="clearfix" action="#" method="POST">
<label>Tahun</label>
<select name="tahun">
<?php
echo "<option value=0 selected>- Pilih Tahun -</option>";
$thn=mysql_query("SELECT * FROM tahun ORDER BY id_thn ASC");
while($thnb=mysql_fetch_array($thn)){
echo "<option value=$thnb[nama_thn]>$thnb[nama_thn]</option>";
}?>
</select>
</form>
<a href="search.php?<?php echo $_POST[tipeku];?>" class="search-btn">Cari</a>
</div>
答案 0 :(得分:1)
试试这个
if(isset($_POST['submit'])) //check if form was submited
{
if(isset($_POST['tipeku']))
{
$tipeku = $_POST['tipeku']; //here you have the value of select box
//save to database or do what you want to do
}
}
?>
<div class="select-form">
<form action="" method="POST"> //make action = '' if want to post to the same page
<label>Tipe</label>
<select name="tipeku">
<?php
echo "<option value='0' selected>- Pilih Tipe -</option>"; //use quotes around the value
$tipe=mysql_query("SELECT * FROM tipe ORDER BY id_tipe ASC");
while($tipeb=mysql_fetch_array($tipe)){
echo "<option value='".$tipeb['nama_tipe']."'>".$tipeb['nama_tipe']."</option>";
}?>
</select>
<input type="submit" value="submit" name="submit" /> <!--Provide submit button to submit the form-->
</form>
</div>
这是一个选择框。如果你想获得所有选择下拉列表的值,请将所有这些值放在<form></form>
标记内,并按上述方式获取它们。