2016-01-22 81 views
0

我想根据下面的数据库显示下拉列表。 (bom table)要显示下拉菜单的值php

例如,当我从下拉列表中选择'Table'时,它会显示bom_description,bom_quantity和UOM。


bom_id |bom_description |product_id |finish_product |bom_quantity |UOM 
1  Table Tops  1   Table    1  /PC 
2  Table Legs  2   Chair    4  /PC 
3  Chair Seat  3        1  /PC 
4  Chair Back  4        1  /PC 
5  Chair Legs  5        4  /PC 

选择产品:表(下拉列表)

(HTML表会显示以下)

bom_description |bom_quantity |UOM 
Table Tops  1    /PC 
Table Legs  4    /PC 

当我点击椅子,它会显示此

选择产品:Chair(A drop下拉列表)

bom_description |bom_quantity |UOM 
Chair Seat  1    /PC 
Chair Back  1    /PC 
Chair Legs  4    /PC 

现在,这是我的代码,但显示内容的html表没有出现。

 <script src="script/jquery-1.11.1.min.js"></script> 
     <script> 
      $(document).ready(function() { 
       $(".itemTypes").change(function() { 
        if (this.value == 0) { 
         $("tr").show(); 
        } 
        else { 
         $("tr").hide(); 
         $(".header").show(); 
         $("." + this.value).show(); 
        } 
       }); 
      }); 
     </script> 

    <?php 
     session_start(); 

    if (!isset($_SESSION['username'])) { 
     header('location: homepage.php'); 
    } 

    //connect to database 
    include ("dbFunctions.php"); 

    $queryBOM = "SELECT * FROM bom"; 

    $resultBOM = mysqli_query($link, $queryBOM) or die(mysqli_error($link)); 
    mysqli_close($link); 
    ?> 

Select Product: 
          <select class="itemTypes"> 
           <option value="0"> 
            all types 
           </option> 
           <?php 
           while ($row1 = mysqli_fetch_array($resultBOM)) { 
            ?> 
            <option value="<?php echo $row1['finish_product']; ?>"> 
             <?php echo $row1['finish_product']; ?> 
            </option> 
           <?php } ?></select> 
          <p> 


           <table border="1"> 
            <tr> 
             <th>BOM Description</th> 
             <th>Quantity</th> 
             <th>UOM</th> 
             <th colspan="2">Action</th> 

             <?php 
             while ($row = mysqli_fetch_assoc($resultBOM)) { 
              $bom_description = $row['bom_description']; 
              $bom_quantity = $row['bom_quantity']; 
              $UOM = $row['UOM']; 
              ?> 

              <tr> 
               <td><center><?php echo $bom_description; ?></center></td> 
               <td><center><?php echo $bom_quantity; ?></center></td> 
               <td><center><?php echo $UOM; ?></center></td> 
               <td><center> 
                 <form method="post" action="editBOM.php"> 
                  <input type="hidden" name="bomID" value="<?php echo $bom_id; ?>" /> 
                  <input type="image" src="images/editicon.png" name="edit" value="edit" style="width:30px;height:30px;"/> 
                </center></form> 
               </td> 
               <td><center> 
                 <form method="post" action="dodeleteBOM.php"> 
                  <input type="hidden" name="bomID" value="<?php echo $bom_id; ?>" /> 
                  <input type="image" src="images/deleteicon.png" name="delete" value="delete" style="width:25px;height:25px;"/> 
                </center></form> 
                </center></td> 
               <?php 
              } 
              ?> 
             </tr> 

如何解决这个问题?

回答

0

我的初步答案是错误的。 您需要重置读取两个循环之间结果的点。

将这个完成创建选择元素之后

<?php mysqli_data_seek($resultBOM, 0); ?> 

如果它没有显示任何的选择框的内容。然后将以下到文件末尾(间ofcourse:

mysqli_close($link); 
+0

嗨,我已经尝试过,但内容不会显示静止 – Janice

+0

是选择填充? –