filter data dengan combobox

annisa · May 3, 2018
saya mau menampilkan data dari tabel jasa, berdasrkan combobox yang ada..saya make method post..disini ada 5 combobox, sebelum dipilih combobox yg awa, combobox selanjutnya nonaktif.. nah jd klo saya cuma pilih beberapa combobox untuk menampilkan data, dia muncul error karena combobox yg nonaktif itu saya panggil method post nya...harusnya seprti apa ya codingannya ??
<!DOCTYPE html>
<!--[if lt IE 7]>      <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]>         <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]>         <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!-->
<html class="no-js">
<!--<![endif]-->

<head>
  <!-- BASICS -->
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <title>Price List</title>
  <meta name="description" content="">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link rel="stylesheet" type="text/css" href="css/isotope.css" media="screen" />
  <link rel="stylesheet" href="js/fancybox/jquery.fancybox.css" type="text/css" media="screen" />
  <link rel="stylesheet" href="css/bootstrap.css">
  <link rel="stylesheet" href="css/bootstrap-theme.css">
  <link rel="stylesheet" href="css/style.css">
  <!-- skin -->
  <link rel="stylesheet" href="skin/default.css">
  <!-- =======================================================
    Theme Name: Amoeba
    Theme URL: https://bootstrapmade.com/free-one-page-bootstrap-template-amoeba/
    Author: BootstrapMade
    Author URL: https://bootstrapmade.com
	 class="navbar-brand"
  ======================================================= -->
</head>

<body>
  <section id="header" class="appear"></section>
  <div class="navbar navbar-fixed-top" role="navigation" data-0="line-height:100px; height:100px; background-color:rgba(0,0,0,0.3);" data-300="line-height:60px; height:60px; background-color:rgba(0,0,0,1);">
    <div class="container">
      <div class="navbar-header">
        <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
						<span class="fa fa-bars color-white"></span>
					</button>
        <h1><a href="pricelist.php" data-0="line-height:90px;" data-300="line-height:50px;"><i class="fa fa-flask fa-2x mar-bot20"></i>  TABELKU
					</a></h1>
      </div>
      <div class="navbar-collapse collapse">
        <ul class="nav navbar-nav" data-0="margin-top:20px;" data-300="margin-top:5px;"> 
          <!--<li class="active"><a href="index.html">Home</a></li>
          <li><a href="#section-about">About</a></li>
          <li><a href="#section-works">Portfolio</a></li>
          <li><a href="#section-contact">Contact</a></li>-->
        </ul>
      </div>
      <!--/.navbar-collapse -->
    </div>
  </div>

  <section class="featured" color="#000000">
    <div class="container" color="#000000">
      <div class="row mar-bot40">
        <div class="col-md-100 col-md-offset-0">

          <div class="align-center" margin-left="10px" >
            <!--<i class="fa fa-flask fa-5x mar-bot20"></i>
            <h2 class="slogan">TABELKU</h2>-->
            <p>
              
			  
			  <html>
<?php
//        koneksi ke database
        //mysql_connect('localhost', 'username', 'password');
        //mysql_select_db('belajar');
		include "config.php";
        ?>
        <form method="post">
            
            <!--sbu-->
			SBU :
            <select class='Menu' style="width:200px" id="sbu" name="sbu">
                <option value=''>Please Select</option>
                <?php
                $query = mysqli_query($db, "SELECT * FROM sbu ORDER BY nm_sbu");
                while ($row = mysqli_fetch_array($query)) {
                ?>
                    <option value="<?php echo $row['kd_sbu']; ?>">
                        <?php echo $row['nm_sbu']; ?>
                    </option>
                <?php
                }
                ?>
            </select>
            
            <!--bid-->
			BIDANG :
            <select class='Menu' style="width:200px" id="bid" name="bid">
                <option value=''>Please Select</option>
                <?php
                $query = mysqli_query($db, "SELECT * FROM bid
                                    INNER JOIN sbu ON bid.kd_sbu = sbu.kd_sbu where bid.operasional = 1 ORDER BY nm_bid");
                while ($row = mysqli_fetch_array($query)) {
                ?>
                    <option id="kota" class="<?php echo $row['kd_sbu']; ?>" value="<?php echo $row['kd_bid']; ?>">
                        <?php echo $row['nm_bid']; ?>
                    </option>
                <?php
                }
                ?>
            </select>
 
            <!--subbid-->
			SUB BIDANG :
            <select class='Menu' style="width:200px" id="subbid" name="subbid">
                <option value=''>Please Select</option>
                <?php
                $query = mysqli_query($db, "SELECT * FROM subbid
                                        INNER JOIN bid ON subbid.kd_bid = bid.kd_bid ORDER BY nm_subbid");
                while ($row = mysqli_fetch_array($query)) {
                ?>
                    <option id="subbid" class="<?php echo $row['kd_bid']; ?>" value="<?php echo $row['kd_subbid']; ?>">
                        <?php echo $row['nm_subbid']; ?>
                    </option>
                <?php
                }
                ?>
            </select>
 
            <!--gkom-->
			GRUP KOMODITI :
            <select class='Menu' style="width:200px" id="gkom" name="gkom">
                <option value=''>Please Select</option>
                <?php
                $query = mysqli_query($db, "SELECT * FROM gkom
                                        INNER JOIN subbid ON gkom.kd_subbid = subbid.kd_subbid ORDER BY nm_gkom");
                while ($row = mysqli_fetch_array($query)) {
                ?>
                    <option id="gkom" class="<?php echo $row['kd_subbid']; ?>" value="<?php echo $row['kd_gkom']; ?>">
                        <?php echo $row['nm_gkom']; ?>
                    </option>
                <?php
                }
                ?>
            </select>
 
            <!--kom-->
			KOMODITI :
            <select class='Menu' style="width:200px" id="kom" name="kom">
                <option value=''>Please Select</option>
                <?php
                $query = mysqli_query($db, "SELECT * FROM komoditi
                                        INNER JOIN gkom ON komoditi.kd_gkom = gkom.kd_gkom ORDER BY nm_komoditi_ind");
                while ($row = mysqli_fetch_array($query)) {
                ?>
                    <option id="kom" class="<?php echo $row['kd_gkom']; ?>" value="<?php echo $row['kd_komoditi']; ?>">
                        <?php echo $row['nm_komoditi_ind']; ?>
                    </option>
                <?php
                }
                ?>
            </select>
        
<td>SEARCH :</td>
<td><input class='search' type="text" name="txtsearch" style="width:200px" value="" /> </td>
<td><input class='cari' type="submit" value="Cari" name="submit" style="width:70px"/></td>
<br></br>

</form>

        <script src="jquery-1.10.2.min.js"></script>
        <script src="jquery.chained.min.js"></script>
        <script>
            $("#bid").chained("#sbu");
            $("#subbid").chained("#bid");
            $("#gkom").chained("#subbid");
            $("#kom").chained("#gkom");
            //$("#subbid").chained("#kom");
        </script>


<!-- tabel -->


<?php  
  if (isset($_POST['submit'])) {
   $search = $_POST['txtsearch'];  
   $sbunya = $_POST['sbu'];  
   $bidnya = $_POST['bid']; 
   $subbidnya = $_POST['subbid']; 
   $gkomnya = $_POST['gkom']; 
   $komnya = $_POST['kom'];
   
   
   if ($bidnya == ''){
	   if ($search == ''){
		  $sql = "SELECT * FROM jasa WHERE kd_sbu = '$sbunya'"; 
	   } else {
		  $sql = "SELECT * FROM jasa WHERE kd_sbu = '$sbunya' and nm_jasa_ind like '%$search%'";
	   }	   
   } else if ($subbidnya == ''){
	   if ($search == ''){
		   $sql = "SELECT * FROM jasa WHERE kd_sbu = '$sbunya' and kd_bid = '$bidnya'";
	   } else {
		   $sql = "SELECT * FROM jasa WHERE kd_sbu = '$sbunya' and kd_bid = '$bidnya' and nm_jasa_ind like '%$search%'";
	   }
   } else if ($gkomnya == ''){
	   if ($search == ''){
	   $sql = "SELECT * FROM jasa WHERE kd_sbu = '$sbunya' and kd_bid = '$bidnya' and kd_subbid = '$subbidnya'";
	   } else {
	   $sql = "SELECT * FROM jasa WHERE kd_sbu = '$sbunya' and kd_bid = '$bidnya' and kd_subbid = '$subbidnya' and nm_jasa_ind like '%$search%'";
	   }
   } else if ($komnya == ''){
	   if ($search == ''){
	   $sql = "SELECT * FROM jasa WHERE kd_sbu = '$sbunya' and kd_bid = '$bidnya' and kd_subbid = '$subbidnya' and kd_gkom = '$gkomnya'";
	   } else {
	   $sql = "SELECT * FROM jasa WHERE kd_sbu = '$sbunya' and kd_bid = '$bidnya' and kd_subbid = '$subbidnya' and kd_gkom = '$gkomnya' and nm_jasa_ind like '%$search%'";
	   }
   } else {
	   if ($search == ''){
	   $sql = "SELECT * FROM jasa WHERE kd_sbu = '$sbunya' and kd_bid = '$bidnya' and kd_subbid = '$subbidnya' and kd_gkom = '$gkomnya' and kd_komoditi = '$komnya'";
	   } else {
	   $sql = "SELECT * FROM jasa WHERE kd_sbu = '$sbunya' and kd_bid = '$bidnya' and kd_subbid = '$subbidnya' and kd_gkom = '$gkomnya' and kd_komoditi = '$komnya' and nm_jasa_ind like '%$search%'";
	   }
   }
   
   $i=1;
   $result = mysqli_query($db, $sql) or die('Error, list jasa failed. ' . mysqli_error());  
       
   if (mysqli_num_rows($result) == 0) { 
    echo '<p></p><p>Pencarian tidak ditemukan</p>';  
   } else {  
    //echo '<p></p>';
	
	echo '<table style="table-layout: fixed" border="2" width="1200px">';	 
     echo '<tr><td width="50px">No.</td>'; 
     echo '<td width="600px">Nama Jasa</td>'; 
     echo '<td width="150px">Methode</td>'; 
     echo '<td width="150px">Persyaratan</td>'; 
     echo '<td width="70px">Sat Harga</td>'; 
     echo '<td width="100px">Harga</td></tr>';
	 
    while ($row = mysqli_fetch_array($result)) {  
     extract($row); 
	$harga = $row['hrg'];
	$hargaa = number_format($harga,0,',','.');
	 
     echo '<tr><td align="top">'.$i.'</td>'; 
     echo '<td align="left">'.$nm_jasa_ind.'</td>';  
     echo '<td align="top">'.$methode.'</td>'; 
     echo '<td align="top">'.$persyaratan.'</td>'; 
     echo '<td align="top">'.$sat_hrg.'</td>'; 
     echo '<td align="right">'.$hargaa.'</td></tr>';  
     $i++;
    }
     echo '</table>';
     echo '<p></p>';
   }
  }
?>  
<!--</form>-->
			  
			  
            </p>
          </div>
        </div>
      </div>
    </div>
  </section>
  </body>

</html>
Silahkan login untuk menjawab!