我有这样的观点
<?php foreach ($category as $c) { ?>
<li><?php echo $c['name_category'];?></li>
<?php foreach ($sub_category as $sc) {
if($sc['id_category']==$c['id_category']) { ?>
<ul>
<li><?php echo $sc['subname_category'];?></li>
</ul>
<?php } } }?>
视图的结果是
但我希望看起来像这样
答案 0 :(得分:0)
在a和css float中包装每个类别:离开它们。
<?php foreach ($category as $c) { ?>
<div>
<li><?php echo $c['name_category'];?></li>
<?php foreach ($sub_category as $sc) {
if($sc['id_category']==$c['id_category']) { ?>
<ul>
<li><?php echo $sc['subname_category'];?></li>
</ul>
<?php }
</div>
}
}?>
答案 1 :(得分:0)
您的外部li
未包装子元素。首先,按如下方式修复PHP代码,并将样式display: inline-block
添加到所有外部元素。
<?php foreach ($category as $c) { ?>
<li style="display: inline-block"><?php echo $c['name_category'];?>
<?php foreach ($sub_category as $sc) {
if($sc['id_category']==$c['id_category']) { ?>
<ul>
<li><?php echo $sc['subname_category'];?></li>
</ul>
<?php } } ?> </li> <?php }?>