0

我正在尝试学习如何编程,这是我的第一个项目。我知道我应该阅读教程,但我有点坚持。真的很想自己完成它,但是越来越令人沮丧..至少有人可以引导我朝着正确的方向前进吗?那么,如何根据下拉列表选择将数据回显到表格单元格?非常感谢任何帮助。到目前为止的代码:http: //jsfiddle.net/uFEPn/3/

<select>
    <option>-- Select lot --</option>
    <?php
    mysql_connect('localhost','root','');
    mysql_select_db('pl_base');
    $query="SELECT DISTINCT  lot_number FROM pl_table";
    $result=mysql_query($query);
    while(list($lot_number)=mysql_fetch_row($result)) {
        echo "<option value=\"".$lot_number."\">".$lot_number."</option>";
    }
   ?>
    </select>
</br>

<table border="1" id="table">
  <tr>
    <th width=80 height=30>Lot<br/>number</th>
    <th width=110 height=30>Description</th>
    <th width=90 height=30>Pallet<br/>number</th>
    <th width=60 height=30>Net</th>
    <th width=60 height=30>Gross</th>
  </tr>
  <tr>
    <td>#</td>
    <td rowspan="5">echo results here</td>
    <td><b>Total</b></td>
    <td>#</td>
    <td>#</td>
  </tr>
    <td> # </td>
    <td colspan="3">#</td>
  </tr>

  <tr>
    <th>&</th>
    <th>&</th>
    <th>&</th>
    <th>&</th>
  </tr>

  </table>

数据库中的表:

+--------------------------+-------------------------+---------+-------+
|    id   |   lot_number   | descr  | pallet_number  | net     | gross |
+--------------------------+-------------------------+---------+-------+
|    1    |       111      |  black |         1      |  800    | 900   |
|    2    |       111      |  black |         2      |  801    | 901   |
|    3    |       111      |  black |         3      |  802    | 902   |
|    4    |       222      |  white |         1      |  800    | 900   |
|    5    |       222      |  white |         2      |  801    | 901   |
|    6    |       222      |  white |         3      |  802    | 902   |
+--------------------------+-------------------------+---------+-------+
4

1 回答 1

0

在选择元素中选择批号不会直接使用 php 更新。由于 php 是一种服务器端语言,因此您必须将数据作为表单提交然后显示。

    <?php 
     mysql_connect('localhost','root','');
        mysql_select_db('pl_base');
        $query="SELECT DISTINCT  lot_number FROM pl_table";
        $result=mysql_query($query);
     ?>  
     <form action="" method="POST">
     <select name="option_chosen">
        <option>-- Select lot --</option>
        <?php
            while(list($lot_number)=mysql_fetch_row($result)) {
            echo "<option value=\"".$lot_number."\">".$lot_number."</option>";
        }
       ?>
        </select>

     <input type="submit" value="Submit" />
    </form>
    </br>

    <table border="1" id="table">
      <tr>
        <th width=80 height=30>Lot<br/>number</th>
        <th width=110 height=30>Description</th>
        <th width=90 height=30>Pallet<br/>number</th>
        <th width=60 height=30>Net</th>
        <th width=60 height=30>Gross</th>
      </tr>

      <?php 
      if($_SERVER['REQUEST_METHOD'] =='POST')
 { $option_chosen=$_POST['option_chosen'];
     $query="SELECT * FROM pl_table WHERE lot_number='$option_chosen'";
     $run=mysqli_query($query);
     $row=mysqli_fetch_array($run, MYSQLI_ASSOC);

    echo "<tr><td>".$row['lot_number']."</td>";
    echo  "<td>".$row['descr']."</td><td>".$row['pallet_number']."</td>";
    echo "<td>".$row['net']."</td><td>".$['gross']."</td></tr>";

}
?>

         </table>
于 2013-06-20T16:50:12.567 回答