【问题标题】:how to fire two query in a function with two different result如何在具有两个不同结果的函数中触发两个查询
【发布时间】:2018-12-19 11:41:52
【问题描述】:

如何在具有两个不同结果的函数中触发两个查询:

$id = $_SESSION['user_id'];
$role = $_SESSION['user_role'];

$this->db->select("date_of_birth");
$this->db->from("student_basic_details");
$this->db->join('users', 'student_basic_details.student_id=users.user_id');
$this->db->where('users.role', $role);
$this->db->where('student_id', $id);
$student_birthday = $this->db->get()->row_array();

$this->db->select('date_of_birth');
$this->db->from('staff_basic_details');
$this->db->join('users', 'staff_basic_details.id=users.user_id');
$this->db->where('users.role', $role);
$this->db->where('id', $id);
$staff_birthday = $this->db->get()->row_array();

print_r($student_birthday);
exit();

但是查询器 $student_birthday 和 $staff_birthday 都返回了相同的结果。

【问题讨论】:

标签: php database codeigniter session


【解决方案1】:

你可以试试这个解决方案来解决你的问题:

$qry1 = $this->db->query("QUERY1");
$qry2 = $this->db->query("QUERY2");

$query = $this->db->query(' (".$qry1.") UNION ALL (".$qry2.") ');

return $query->result();

希望对你有帮助。

【讨论】:

    【解决方案2】:

    在模型中尝试:

    $qry1 = $this->db->query("QUERY1");
    $qry2 = $this->db->query("QUERY2");
    
    $res1 = $qry1->result();
    $res2 = $qry2->result();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-08-08
      • 1970-01-01
      • 2013-06-01
      • 2021-11-13
      • 1970-01-01
      相关资源
      最近更新 更多