繁体   English   中英

Codeigniter,选择,结果,数组格式

[英]Codeigniter, Select, Result, Array Format

我正在使用Codeigniter,我从两个表( countrycity )中选择了所有(*)数据。 这些表都有一个ID字段,当我打印结果时,数组中只有一个ID元素。

国家表的字段:

  1. ID;
  2. 名称;
  3. 旗;
  4. 主席。

城市表的字段:

  1. ID;
  2. ctry_id; (国家/地区编号)
  3. 名称。

这是我的代码点火器代码:

$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.

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM