具体数组中添加数组代码如下:
function city($cityid){
$city = $this->db->query("select * from info_city where id = $cityid");
$city = $city->row_array();
$syset = new sysSetting();
$remstr = $syset->setRecommand_citySuffix($city['city']);
$cates = $this->db->query("select * from info_category");
$cates = $cates->result_array();
foreach ($cates as $cate)
{
$cateid = $cate['id'];
$subcates = $this->db->query("select * from info_subcate where cateid = $cateid ");
$cate['subcates']=$subcates->result_array();
array_push($cates,$cate);
}
$data['cates']=$cates;
print_r($cates);
$data['title']=$remstr;
$data['kwd']=$remstr;
$data['des']=$remstr;
$this->load->view('inc/info/header',$data);
$this->load->view('info/city');
$this->load->view('inc/footer');
}
打印数据为:
Array ( [0] => Array ( [id] => 1 [category] => 房产信息 ) [1] => Array ( [id] => 2 [category] => 车辆买卖与服务 ) [2] => Array ( [id] => 3 [category] => 交友征婚 ) [3] => Array ( [id] => 1 [category] => 房产信息 [subcates] => Array ( [0] => Array ( [id] => 1 [cateid] => 1 [subcate] => 房屋出租 ) [1] => Array ( [id] => 2 [cateid] => 1 [subcate] => 房屋合租 ) [2] => Array ( [id] => 3 [cateid] => 1 [subcate] => 房屋求租 ) ) ) [4] => Array ( [id] => 2 [category] => 车辆买卖与服务 [subcates] => Array ( ) ) [5] => Array ( [id] => 3 [category] => 交友征婚 [subcates] => Array ( ) ) )
页面的输出:
<?php foreach($cates as $cate):?>if($cate['subcates']!=null){
?>
}
?>
出现的问题:
Severity: Notice
Message: Undefined index: subcates
Filename: info/city.php
Line Number: 12
请大家帮我看一下哈。。。。
该问题想了好久了。。不知道如何解决。。以前总是避开该问题。。唉。。总算是又遇到了。。。