【问题标题】:inset data into table with foreign key and display a single data containing the information of both table使用外键将数据插入表中并显示包含两个表信息的单个数据
【发布时间】:2016-09-06 06:03:53
【问题描述】:

我想显示包含外键的表中的信息。 我只想显示该表中的一个数据以及与外键相关的另一个表的相关信息。

请帮忙

问题是只显示

型号

function getreport() {
   $query = $this->db->get('labreport_db');
   $res = $this->db->query("SELECT labreport_db.R_ID, patient_db.name, labreport_db.Doctor
FROM labreport_db INNER JOIN patient_db
ON labreport_db.P_ID=patient_db.id;");
    return $res->result();
}

控制器

public function reportDisplay(){
  $data['posts'] = $this->labdoc_model->getreport();

  $this->load->view('SystemAdminUser/labreport',$data);
}

【问题讨论】:

  • 包含您尝试过的代码...
  • 到目前为止你尝试了什么?

标签: php sql codeigniter model controller


【解决方案1】:

您可以将左外连接或右外连接where子句一起使用,使用带有where条件的连接,您可以轻松地显示表中的一个数据和另一个表中的相关信息。 .

例如:

select table1.id,table1.name,table2.address from table1 left outer join table2 on table1.id=table2.id where table1.id="123"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-05-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多