我有从数据库中获取数据的菜单 这是我的代码
<nav id="mysidebarmenu" class="amazonmenu">
<ul>
<?php
//Get Category array
$categories = json_decode($this->db->get_where('ui_settings', array('type' => 'home_category'))->row()->value);
foreach ($categories as $row) {
?>
<li>
<a href="javascript:void(0);">
<?php
echo $this->crud_model->get_type_name_by_id('category', $row, 'category_name');
?>
</a>
<div>
<div class="col-md-12">
<?php
//Get Sub Category array
$subs = $this->db->get_where('sub_category', array('category' => $row['category_id']))->result_array();
foreach ($subs as $row1) {
$this->db->limit(4);
$this->db->order_by('product_id', 'desc');
$products = $this->db->get_where('product', array('sub_category' => $row1['sub_category_id'], 'status' => 'ok'))->result_array();
?>
<div class="col-md-12"><h3 class="text-center" style="background:#EAEAEA;"><?php echo $row1['sub_category_name']; ?></h3></div>
<?php
foreach ($products as $row2) {
if ($this->crud_model->is_publishable($row2['product_id'])) {
?>
<div class="col-md-3">
<div class="menu_box">
<div class="img_menu_box" style="background:url('<?php echo $this->crud_model->file_view('product', $row2['product_id'], '', '', 'no', 'src', 'multi', 'one') ?>') no-repeat center center; background-size: 100% auto;">
</div>
<a href="<?php echo $this->crud_model->product_link($row2['product_id']); ?>">
<?php echo $row2['title']; ?>
</a>
</div>
</div>
<?php
}
}
?>
<?php
}
?>
</div>
</div>
</li>
<?php
}
?>
</ul>
这是我得到的结果
的print_r($类别);
result = Array([0] =&gt; 5 [1] =&gt; 31)
的print_r($潜艇);
1- [Array] [0] =&gt;的结果5 =([0] =&gt;数组([sub_category_id] =&gt; 18 [sub_category_name] =&gt; A [类别] =&gt; 5)[1] =&GT;数组([sub_category_id] =&gt; 19 [sub_category_name] =&gt; B [类别] =&gt; 5))
数组[1] =&gt;的结果31 = Array()
问题是第二个数组结果变空
1- **category table & data**
category_id | category_name
5 cat1
31 cat2
2- **Sub category table & data**
sub_category_id | sub_category_name | category
1 C 31
2 D 31
18 A 5
19 B 5
3- ui_settings table & data
ui_settings_id | type | value
10 home_category ["5","31"]
预期结果
数组[1] =&gt; 31 =([0] =&gt;数组([sub_category_id] =&GT; 1 [sub_category_name] =&gt; C [类别] =&gt; 31)[1] =&gt;数组([sub_category_id] =&gt; 2 [sub_category_name] =&gt; D [category] =&gt; 31))
答案 0 :(得分:1)
如果category = 31
有任何记录,首先检查表格&gt; sub_category