【发布时间】:2021-12-29 02:39:56
【问题描述】:
试图交叉引用 2 个表中的数据,只显示其中 1 个表中的数据...
如果表 001 中的“区”与表 002 中的“区”匹配,那么我想从表 002 中回显相应的“协调员”
表 001
| month_of_report | district | org |
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| January | 004 | Dallas |
| February | 029 | Dallas |
| March | 047 | Dallas |
表 002
| coordinator | district |
- - - - - - - - - - - - - - -
| Jamie | 004 |
| Susie | 047 |
| Jimmy | 029 |
型号
public function reg_co()
{
$this->db->where('report_month', $report_month);
$query = $this->db->get('non_clinical_total_tests');
$this->db->select('*');
$this->db->from('coordinator');
$this->db->join('non_clinical_total_tests', 'non_clinical_total_tests.district = coordinator.district');
if($query->num_rows() > 0)
{
return $query->row();
}
}
控制器
$data['reg_co'] = $this->Page_model->reg_co();
查看文件
<?php if($reg_co) : ?>
<strong>DISTRICT: </strong><?php echo $reg_co->district; ?><br>
期望的结果
如果 2 个表中的地区匹配,那么我应该能够回应该地区的协调员。
【问题讨论】: