I'm using Codeigniter, I selected all (*) data from two tables ( country
and city
). Those tables have an ID
fields, when I print the result there is only one ID
element in array.
The country table's fields:
The city table's fields:
This is my codeigniter code:
$this->db->select('country.*, city.*');
$this->db->from('country');
$this->db->join('city', 'city.ctry_id = country.id', 'left');
$this->db->where('country.name', 'Tajikistan');
$qry = $this->db->get();
// Testing purpose only [do not judge ;)]
echo '<pre>';
print_r($qry->result());
echo '</pre>';
Expected result:
id => 1,
name => 'Tajikistan',
flag => 'tj.png',
president => 'Emomali Rahmon',
id => 1,
ctry_id => 1,
name => 'Dushanbe'
.
.
.
Result that I got:
id => 1,
name => 'Dushanbe',
flag => 'tj.png',
president => 'Emomali Rahmon',
ctry_id => 1
.
.
.
Any help will be appreciated.
I solved this 'problem' using pseudonym, or prefix for every column, for example:
The country table's fields:
ctry_id;
ctry_name;
ctry_flag;
ctry_president.
The city table's fields:
cty_id;
cty_ctry_id; (country id)
cty_name.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.