How to bring out checboxes based on drop down list selection from DB

Posted by user2199877 on Stack Overflow See other posts from Stack Overflow or by user2199877
Published on 2013-07-03T17:02:39Z Indexed on 2013/07/03 17:05 UTC
Read the original article Hit count: 174

Filed under:
|

I got stuck again. Can't overcome this step: loop through (in a form of checkboxes) pallets based on the lot drop down list selection, so it can be further submitted to complete the table. Please, please help. So, basically, first submit button (drop down menu) brings into the table lot number and description and also checkboxes to choose pallets. Second submit button (checboxes) brings into the table pallets numbers and weights. Thank you for any help.

     <?php 
     mysql_connect('localhost','user','');
     mysql_select_db('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' name='submitLot' value='Submit' />
    </form>


    <!-- need help here
    <h4>-- Select pallets --</h4>
    <form action="" method="POST">

    <input type='submit' name='submitPal' value='Submit'/>
    </form>
    -->

    <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=mysql_query($query);
     $row=mysql_fetch_array($run, MYSQLI_ASSOC);

    echo "<tr><td>".''."</td>";
    echo "<td rowspan='5'>".$row['descr']."</td>";
    echo "<td><b>".'Total weight'."<b></td>";
    echo "<td>".''."</td><td>".''."</td></tr>";

    echo "<td>".$row['lot_number']."</td>";
    echo "<td colspan='3'>".''."</td>";

    //This to be echoed when "select pallets" submited
    //echo "<tr><td>".$row['lot_number']."</td>";
    //echo "<td>".$row['pallet_number']."</td>";
    //echo "<td>".$row['net']."</td><td>".$row['gross']."</td></tr>";

}
?>

    </table>

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

© Stack Overflow or respective owner

Related posts about php

Related posts about mysql