php - 如何从它的孩子那里得到父母的名字?
问题描述
我将为我的最后一年项目建立一个动态的产品类别。我尝试了树方式,但不知何故让我感到困惑,所以我决定让它变得简单。我想显示 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>
这是我的数据库表
我想让它看起来像这样
解决方案
推荐阅读
- c - Tcp 和 udp 最大数据包大小
- json - 使用 jq json cli 以千位分隔符格式化数字
- c# - 如何在 VS2019 中启用编辑并继续?
- typescript - 检索 ng-select 的选定值 - Angular8
- javascript - 仅使用 Sublime Text 作为 IDE 时 Meteor 不刷新浏览器
- javascript - 使用 JavaScript 将 HTML div 排序到其对应的 div
- angular - 如何将新字体导入项目 - Angular 6
- c++ - Armadillo C++ - 从常量内存初始化只读矩阵而不复制
- jquery - Jquery DataTable 下一页表单提交问题
- c# - 将返回值从 exe 传递给 bat 并将其传递给 C# 中的 Process