使用codeigniter查询

时间:2016-12-22 12:33:16

标签: php mysql codeigniter

我正在尝试从数据库执行报告,用户将输入自己的标准来提取数据,

这是我的提取的模态功能,

public function fetch_insight($insight_start, $insight_end, $user_id,
      $manager_id, $category_id, $expense_method, $report_status, $policy_breach)
{

  $array = array('ec_expensedetails.expense_date >'         => $insight_start,
          'ec_expensedetails.expense_date <='   => $insight_end,
          'ec_reports.report_status'            => $report_status,
          'ec_expensedetails.user_id' => $user_id,
          'ec_reports.manager_id' => $manager_id,
          'ec_expensedetails.category_id' =>  $category_id,
          'ec_expensedetails.expense_method'  =>  $expense_method,
          'ec_expensedetails.policy_breach' =>  $policy_breach);
  $this->db->where($array);

  $this->db->select('ec_expensedetails.*');
  $this->db->select('ec_expensecategory.*');
  $this->db->select('ec_reports.*');
  $this->db->select('ec_users.*');
  $this->db->from('ec_users');
  $this->db->join('ec_expensedetails', 'ec_expensedetails.user_id = '.$user_id,'INNER');
  $this->db->join('ec_expensecategory', 'ec_expensecategory.category_id = ec_expensedetails.category_id','INNER');
  $this->db->join('ec_reports', 'ec_reports.report_status = ec_reports.report_status ','INNER');
  return $this->db->get()->result_array();
}

现在,当用户选择$user_id, $manager_id, $category_id,之类的字段时,它会给我结果数组,

问题,

  1. 但是示例如果用户只想在没有任何其他条件的情况下提取日期数据,我该如何删除user_id,manager_id,category_id条件下的其他条件?

  2. JOIN中的report_status是列值字段,我可以连接具有ID字段的表,但是如何在codeigniter中使用值字段连接表?请参阅最后一次加入代码。

  3. 谢谢,

0 个答案:

没有答案