如何从孩子那里获得父母的名字?

时间:2018-08-08 05:15:37

标签: php mysql

在我的最后一年的项目中,我将用他们的潜艇建立一个动态的产品类别。我尝试了树的方式,但是以某种方式使我感到困惑,所以我决定将其简化。我想显示Clothe的父母姓名。我想这样显示 我可以这样做吗?

这是我的PHP代码

<form method="post" action="product_category_add_exec.php" enctype="multipart/form-data">

                                    <div class="form-group">
                                        <label for="recipient-level" class="control-label"> Parent Category</label>
                                        <select class="form-control" name="admin_lid" required="">                                    

                                            <option></option>
                                    <?php
                                            $sql_pcat = "SELECT * FROM product_category";
                                            $select_pcat = mysqli_query($db,$sql_pcat) or die (mysqli_error().$sql_pcat);

                                            $x =1;

                                            while($list_pcat = mysqli_fetch_array($select_pcat))
                                            {

                                                $product_cat_id = $list_pcat['product_cat_id'];
                                                $parent_id = $list_pcat['parent_id'];
                                                $product_cat_name = $list_pcat['product_cat_name'];
                                    ?>

                                            <?php 
                                                    if ($parent_id == 0)
                                                    {
                                            ?>
                                            <option value = "<?php echo $product_cat_id;?>"><?php echo $product_cat_name; ?></option>
                                            <?php
                                                } else 
                                                    {
                                                $sql_cat = "SELECT * FROM product_category WHERE parent_id= $parent_id ORDER BY product_cat_name ASC";
                                                $select_cat = mysqli_query($db,$sql_cat) or die (mysqli_error().$sql_cat);



                                                $list_cat = mysqli_fetch_array($select_cat);


                                                $product_cat_id = $list_cat['product_cat_id'];
                                                $parent_id = $list_cat['parent_id'];
                                                $product_cat_name = $list_cat['product_cat_name'];  

                                            ?>

                                            <option value = "<?php echo $parent_id;?>">--<?php echo $parent_id;?><?php echo $product_cat_name; ?></option>
                                            <?php
                                                }
                                            ?>
                                    <?php
                                            $x++;
                                            }
                                    ?>

                                        </select>
                                    </div>

                                    <div class="form-group">
                                        <label for="recipient-category" class="control-label">Product Name </label>
                                        <input type="text" class="form-control" id="recipient-category" name="product_cat_name">
                                    </div>
                            </div>


                                <div class="modal-footer">
                                    <button type="submit" class="btn btn-info">Add</button>
                                    <button type ="reset" class ="btn btn-danger">Reset</button>

                                </div>
                                    </form>


这是我的数据库表 img

我想让它看起来像这样

img

0 个答案:

没有答案