douhuang3740 2016-01-23 00:46
浏览 49
已采纳

根据id PHP绑定下拉列表

I would like to display drop down list according to the database below. (bom table)

For example, when I choose 'Table' from the drop down list, it would display the bom_description, bom_quantity and 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

Select Product: Table (A drop down list)

(HTML table will display these)

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

When I click on Chair, it will show this

Select Product: Chair (A drop down list)

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

Right now, this is my code but the html table to display the content are not appearing.

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

How to solve this problem?

  • 写回答

1条回答 默认 最新

  • dspld86684 2016-01-23 02:01
    关注
    You can do it in following way:-
    
    <script src="//code.jquery.com/jquery-1.12.0.min.js"></script>
        <script>
            $(document).ready(function () {
                $(".itemTypes").change(function () {
                    var vall= $(this).val();
                    if ( vall== 0) {
                        $("tr").show();
                    }
                    else {
                        $('form#abc').submit();
                    }
                });
            });
        </script>
    
    <?php
        session_start();
    
    if (!isset($_SESSION['username'])) {
        header('location: homepage.php');
    }
    
    //connect to database
    include ("dbFunctions.php");
    $post_data='';
    if(isset($_POST['value'])){
        $post_data = $_POST['value'];
        $queryBOM1 = "SELECT * FROM bom WHERE bom_description LIKE '%".$_POST['value']."%'";
    }else{
    $queryBOM1 = "SELECT * FROM bom";   
    }
    $queryBOM2= "SELECT * FROM bom";
    
    $resultBOM = mysqli_query($link, $queryBOM2) or die(mysqli_error($link));
    $resultBOM1 = mysqli_query($link, $queryBOM1) or die(mysqli_error($link));
    mysqli_close($link);
    ?>
    
    Select Product:
                           <form action = "<?php echo $_SERVER['REQUEST_URI'];?>" method="POST" id="abc">
                            <select class="itemTypes" name="value">
                                <option value="0">
                                    all types
                                </option>
                                <?php
                                while ($row1 = mysqli_fetch_array($resultBOM)) {
                                    ?>
                                    <option value="<?php echo $row1['finish_product']; ?>" <?php if($row1['finish_product']==$post_data){echo "selected";}?>>
                                        <?php echo $row1['finish_product']; ?>
                                    </option>
                                <?php }?></select>
    </form>
                            <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($resultBOM1)) {
                                            $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>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置