我有两个表格 table1
ID名称价格
1 name1 100
2 name2 200
表2
id authorityId agency start_date end_date
1 1 agency1 1-2-2015 2-12015
我想在第二个表中搜索哪个值适合我 但是我希望第一个表中的名字是基于外键(table1_id)。我怎么能这样做。任何帮助都会受到赞赏吗?
这是我的代码
控制器:
public function searchResult()
{
$search_term = array(
'authorityId' => $this->input->get('authority'),
'grantVillage' => $this->input->get('village'),
'startDate' => $this->input->get('startDate'),
'endDate' => $this->input->get('endDate'));
//print_r($search_term);
$data['searchResult'] = $this->grant_model->searchResult($search_term);
$this->load->view('searchResult',$data);
}
型号:
public function searchResult($search_term)
{
$this->db->select('*');
$this->db->from('grant_data');
$this->db->like('authorityId', $search_term['authorityId']);
$this->db->like('grantVillage', $search_term['grantVillage']);
$this->db->like('startDate', $search_term['startDate']);
$this->db->like('certificate', $search_term['certificate']);
$this->db->like('endDate', $search_term['endDate']);
$query = $this->db->get();
return $query->result();
}