CODEIGNITER,来自 2 个表的参考数据显示在视图文件中
CODEIGNITER, Reference data from 2 tables to show in view file
正在尝试交叉引用来自 2 table 秒的数据并且仅显示来自 table 秒中的 1 秒的数据...
如果 table 001 中的“地区”与 table 002 中的“地区”匹配,那么我想从 table 002
TABLE001
| month_of_report | district | org |
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| January | 004 | Dallas |
| February | 029 | Dallas |
| March | 047 | Dallas |
TABLE002
| 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 table 的学区匹配,那么我应该能够回复该学区的协调员。
________________________________________________________________________________
//This code is for single record from database
//Model function
public function reg_co()
{
$this->db->select('non_clinical_total_tests.*');
$this->db->from('non_clinical_total_tests');
$this->db->join('coordinator', 'coordinator.district = non_clinical_total_tests.district');
$this->db->where('non_clinical_total_tests.report_month', $report_month);
$this->db->limit(1);
if($this->db->num_rows() > 0)
{
return $this->db->get()->row();
}
return false;
}
//View file
<?php if($reg_co) : ?>
<strong>DISTRICT: </strong><?php echo $reg_co->district; ?><br>
_____________________________________________________________________________________
//This code is for all records from database
//Model function
public function reg_co()
{
$this->db->select('non_clinical_total_tests.*');
$this->db->from('non_clinical_total_tests');
$this->db->join('coordinator', 'coordinator.district = non_clinical_total_tests.district');
$this->db->where('non_clinical_total_tests.report_month', $report_month);
if($this->db->num_rows() > 0)
{
return $this->db->get()->result_array();
}
return false;
}
//View file
<?php if($reg_co) : ?>
<?php foreach($reg_co as $reg) { ?>
<strong>DISTRICT: </strong><?php echo $reg['district']; ?><br>
<?php } ?>
正在尝试交叉引用来自 2 table 秒的数据并且仅显示来自 table 秒中的 1 秒的数据...
如果 table 001 中的“地区”与 table 002 中的“地区”匹配,那么我想从 table 002
TABLE001
| month_of_report | district | org |
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| January | 004 | Dallas |
| February | 029 | Dallas |
| March | 047 | Dallas |
TABLE002
| 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 table 的学区匹配,那么我应该能够回复该学区的协调员。
________________________________________________________________________________
//This code is for single record from database
//Model function
public function reg_co()
{
$this->db->select('non_clinical_total_tests.*');
$this->db->from('non_clinical_total_tests');
$this->db->join('coordinator', 'coordinator.district = non_clinical_total_tests.district');
$this->db->where('non_clinical_total_tests.report_month', $report_month);
$this->db->limit(1);
if($this->db->num_rows() > 0)
{
return $this->db->get()->row();
}
return false;
}
//View file
<?php if($reg_co) : ?>
<strong>DISTRICT: </strong><?php echo $reg_co->district; ?><br>
_____________________________________________________________________________________
//This code is for all records from database
//Model function
public function reg_co()
{
$this->db->select('non_clinical_total_tests.*');
$this->db->from('non_clinical_total_tests');
$this->db->join('coordinator', 'coordinator.district = non_clinical_total_tests.district');
$this->db->where('non_clinical_total_tests.report_month', $report_month);
if($this->db->num_rows() > 0)
{
return $this->db->get()->result_array();
}
return false;
}
//View file
<?php if($reg_co) : ?>
<?php foreach($reg_co as $reg) { ?>
<strong>DISTRICT: </strong><?php echo $reg['district']; ?><br>
<?php } ?>