1

我需要一些帮助。我在下面有一些代码,我的问题是,选择时如何检索每个组合值?我真的对此感到困惑。任何帮助将不胜感激,非常感谢。

这是第一个组合框

<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>

这是第三个组合框

<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>

这是第四个组合框

<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>
4

1 回答 1

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>标签内并按照我上面的描述获取它们。

于 2013-06-20T21:41:53.720 回答