How to SELECT data from two tables which share the same column structure using CodeIgniter
I have two tables in one database.
One table can be filled by the customers and one by us. The two tables have the same columns. How can I get data from two tables in one foreach?
I have tblexample and tbluserexample.
This is my current get function:
public function get($id = '', $where = array())
{
$this->db->select('*,tblexample.id as exampleid');
$this->db->from('tblexample');
$this->db->where($where);
if (is_numeric($id)) {
$this->db->where('tblexample.id', $id);
$example = $this->db->get()->row();
if ($example) {
$example->attachment = '';
$example->filetype = '';
$example->attachment_added_from = 0;
$this->db->where('rel_id', $id);
$this->db->where('rel_type', 'example');
$file = $this->db->get('tblfiles')->row();
if ($file) {
$example->attachment = $file->file_name;
$example->filetype = $file->filetype;
$example->attachment_added_from = $file->staffid;
}
}
return $example;
}
return $this->db->get()->result_array();
}