php - 在 php 表中显示不同的级别
问题描述
我有一个自动填充 foreaches 的表格,我需要在每个级别添加一个数字和一个点。我对每个类别/子类别都有一个 foreach 和一个计数
前任。类别 1。子类别 1.1 子类别 1.1.1。
就这样。
我现在所拥有的仅显示第一个类别和子类别。
$i = 1;
$is = 1.1;
$if = '1.1.1';
$iff = '1.1.1.1';
?>
<!-- TABELA DE CATEGORIAS -->
<table class="table">
<thead>
<tr>
<th style="width:50%;">Categoria</th>
<th style="width:70%">Descrição</th>
<th>Ações</th>
</tr>
</thead>
<tbody>
<!-- PEGANDO AS CATEGORIAS -->
<?php
foreach ($exibiCategoria as $registro) :
?>
<tr>
<td><?php echo $i, '. ' . $registro['nome_categoria'] ?></td>
<td><?php echo $registro['desc_categoria'] ?></td>
<td class="table-action">
<a data-toggle="modal" data-target="#cadastrarSubCatModal"><i class="align-middle" data-feather="plus-circle"></i></a>
<a href="?router=Orcamento/modalCat/&id_categoria=<?php echo base64_encode($registro['id_categoria']) ?>"><i class="align-middle" data-feather="edit-2"></i></a>
<a href="?router=Orcamento/modalDelete/&id_categoria=<?php echo base64_encode($registro['id_categoria']) ?>"><i class="align-middle" data-feather="trash"></i></a>
</td>
</tr>
<!-- FIM CATEGORIAS -->
<!-- PEGANDO AS SUB CATEGORIAS -->
<?php
foreach ($exibiCategoriaSub as $registroSub) :
if ($registroSub['id_categoria'] == $registro['id_categoria']) {
?>
<tr>
<td><?php echo " " . $is, '. ' . $registroSub['nome_sub_categoria'] ?></td>
<td><?php echo $registroSub['desc_sub_categoria'] ?></td>
<td class="table-action">
<a data-toggle="modal" data-target="#cadastrarCatFilhaModal"><i class="align-middle" data-feather="plus-circle"></i></a>
<a href="?router=Orcamento/modalSubCat/&id_categoria=<?php echo base64_encode($registro['id_categoria']) ?>"><i class="align-middle" data-feather="edit-2"></i></a>
<a href="?router=Orcamento/modalDeleteSubCat/&id_categoria=<?php echo base64_encode($registroSub['id_sub_categoria']) ?>"><i class="align-middle" data-feather="trash"></i></a>
</td>
</tr>
<?php
?>
<!-- FIM SUB CATEGORIA -->
<!-- FPEGANDO CATEGORIA FILHA -->
<?php
}
foreach ($exibiCategoriaFilha as $registroFilha) :
if ($registroSub['id_categoria'] == $registro['id_categoria']) {
if ($registroSub['id_sub_categoria'] == $registroFilha['id_sub_categoria']) {
?>
<tr>
<td><?php echo " " . $if, '. ' . $registroFilha['nome_categoria_filha'] ?> </td>
<td> <?php echo $registroFilha['desc_categoria_filha'] ?></td>
<td> <?php echo $registroFilha['id_categoria_filha'] ?></td>
<td class="table-action">
<a data-toggle="modal" data-target="#cadastrarCatFilhaFModal"><i class="align-middle" data-feather="plus-circle"></i></a>
<a href="?router=Orcamento/modalCatFilha/&id_categoria=<?php echo base64_encode($registroFilha['id_categoria_filha']) ?>"><i class="align-middle" data-feather="edit-2"></i></a>
<a href="?router=Orcamento/modalDeleteCatFilha/&id_categoria=<?php echo base64_encode($registroFilha['id_categoria_filha']) ?>"><i class="align-middle" data-feather="trash"></i></a>
</td>
</tr>
<!-- FIM CATEGORIA FILHA -->
<!-- FPEGANDO CATEGORIA FILHA DA FILHA-->
<?php
}
}
foreach ($exibiCategoriaFilhaF as $registroFilhaF) :
if ($registroSub['id_categoria'] == $registro['id_categoria']) {
if ($registroSub['id_sub_categoria'] == $registroFilha['id_sub_categoria']) {
if ($registroSub['id_sub_categoria'] == $registroFilhaF['id_sub_categoria']) {
if ($registroFilha['id_categoria_filha'] == $registroFilhaF['id_cat_filha']) {
?>
<tr>
<td><?php echo " " . $iff, '. ' . $registroFilhaF['nome_categoria_filha'] ?> </td>
<td> <?php echo $registroFilhaF['desc_categoria_filha'] ?></td>
<td> <?php echo $registroFilhaF['id_cat_filha'] ?></td>
<td> <?php echo $registroFilha['id_categoria_filha'] ?></td>
<td class="table-action">
<a data-toggle="modal" data-target="#cadastrarCatFilhaFFModal"><i class="align-middle" data-feather="plus-circle"></i></a>
<a href="?router=Orcamento/modalCatFilha/&id_categoria=<?php echo base64_encode($registroFilhaF['id_categoria_filha']) ?>"><i class="align-middle" data-feather="edit-2"></i></a>
<a href="?router=Orcamento/modalDeleteCatFilha/&id_categoria=<?php echo base64_encode($registroFilha['id_categoria_filha']) ?>"><i class="align-middle" data-feather="trash"></i></a>
</td>
</tr>
<!-- FIM CATEGORIA FILHA DA FILHA -->
<?php
}
}
}
}
endforeach;
$i++;
$is++;
$if++;
$iff++;
endforeach;
endforeach;
endforeach;
?>
</td>
</tr>
</tbody>
</table>
解决方案
推荐阅读
- php - 试图获取非对象的属性“员工”(查看:/Applications/MAMP/htdocs/al-halal/resources/views/leave/allLeave.blade.php)
- django - Django 将额外数据传递给从 ModelViewSet serializer.save() 创建的 ModelSerializer
- java - 在 Quarkus 中使用 ResourceLoader
- html - Angular Html + Css = PDF,生成正确 PDF 的问题
- kotlin - Mockk - 模拟 javax.mail.Message - 获取 java.lang.VerifyError
- python-3.x - requirements.txt 中的库会安装自己的依赖项吗?
- android - RxJava 主题和可完成
- php - 为什么 array() 和 [] 在此示例中的行为不同
- node.js - 如何将带有-T的curl命令转换为节点js中的axios以将文件上传到azure datalake
- c++ - 为什么在使用可变参数时调用 copy-ctor 而不是隐式转换运算符