我的桌子
tbl_company(id,user_id,name,description)
tbl_project(id,name,company_id)
在控制器中:
public function manage() {
$this->load->model('company/companymodel');
$companys = $this->companymodel->get();
$companydata = array();
foreach ($companys as $key => $company) {
$companydata[$key] = $company;
//$this->load->model('projectmodel');
$Projects = $this->projectmodel->get($company->company_id);
//debug($Projects);
$companydata[$key]->projects = $Projects;
}
//debug($companydata);
$data = array(
'content' => 'project/manage',
'companydata' => $companydata,
);
//debug($data);
$this->load->view('dashboard_wrapper',$data);
}
在视图中:
<div class="box-content">
<table class="table table-striped table-bordered bootstrap-datatable datatable">
<?php foreach( $companydata as $company){ ?>
<h3><?php echo $company->company_name; ?></h3>
<?php foreach($company->projects as $project) { ?>
<li><?php echo $project->name; ?></li>
<?php } ?>
<?php } ?>
</table>
</div>
我需要在相关公司的相关项目中显示: