PHP:使用4下拉列表输出数据

时间:2019-05-08 09:48:58

标签: php jquery mysql

我需要帮助,我想基于4个下拉菜单输出一个值。因此,假设我在mysql中有一些表:

    Tablekind   tabled1   tabled2  tabled3
    id   kind   id dim1   id dim2  id dim3
    1    x       1 a      1  c     1  e
    2    y       2 b      2  d     2  f

Tableprice
id kind dim1 dim2 dim3 price
1  x    a    c    e    1000
2  x    a    c    f    1100
3  x    a    d    e    1200
4  x    a    d    f    1100
.  .    .    .    .    .

因此,用户将从tablekind,tabled1,tabled2和tabled3生成的四个下拉列表中进行选择,并将价格作为输出 我可以用一些js并嵌套,如果没有的话,但是我认为从db获取数据要好得多

 <html>
 <head>
 <script src="//code.jquery.com/jquery-1.11.2.min.js"></script>
 </head>

 <body>

 <select id="selectkind">
    <option>-- Select item --</option>
      <?php
        $mysqli = new mysqli("localhost", "root", "","my_db");
        $results = $mysqli->query("SELECT * FROM kind");
        $kind = array(); 
        if ($results) { 
           while($obj = $results->fetch_object()){
             echo '<option value="'.$obj->kind.'">'.$obj->kind.'</option>';
           }
        }
      ?>
  </select>
  <select id="selectd1">
    <option>-- Select item --</option>
      <?php
        $mysqli = new mysqli("localhost", "root", "","my_db");
        $results = $mysqli->query("SELECT * FROM tabled1");
        $dim1= array(); 
        if ($results) { 
           while($obj = $results->fetch_object()){
             echo '<option value="'.$obj->dim1.'">'.$obj->dim1.'</option>';
           }
        }
      ?>
    </select>
   <select id="selectd2">
    <option>-- Select item --</option>
      <?php
        $mysqli = new mysqli("localhost", "root", "","my_db");
        $results = $mysqli->query("SELECT * FROM tabled2");
        $dim2= array(); 
        if ($results) { 
           while($obj = $results->fetch_object()){
             echo '<option value="'.$obj->dim2.'">'.$obj->dim2.'</option>';
           }
        }
      ?>
    </select>
    <select id="selectd3">
    <option>-- Select item --</option>
      <?php
        $mysqli = new mysqli("localhost", "root", "","my_db");
        $results = $mysqli->query("SELECT * FROM tabled3");
        $dim3= array(); 
        if ($results) { 
           while($obj = $results->fetch_object()){
             echo '<option value="'.$obj->dim3.'">'.$obj->dim3.'</option>';
           }
        }
      ?>
    </select>


Price: <div id="price"></div>
....

我需要帮助来检查此部分并完成脚本以从db获取数据 谢谢

0 个答案:

没有答案