我使用的是Codeigniter,我从两个表(country
和city
)中选择了所有(*)数据。这些表都有一个ID
字段,当我打印结果时ID
,数组中只有一个元素。
国家表的字段:
城市表的字段:
这是我的代码点火器代码:
$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>';
预期结果:
id => 1,
name => 'Tajikistan',
flag => 'tj.png',
president => 'Emomali Rahmon',
id => 1,
ctry_id => 1,
name => 'Dushanbe'
.
.
.
我得到的结果是:
id => 1,
name => 'Dushanbe',
flag => 'tj.png',
president => 'Emomali Rahmon',
ctry_id => 1
.
.
.
任何帮助将不胜感激。
我使用化名或每列的前缀解决了这个“问题”,例如:
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.
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句