简体   繁体   English

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

[英]Codeigniter, Select, Result, Array Format

I'm using Codeigniter, I selected all (*) data from two tables ( country and city ). 我正在使用Codeigniter,我从两个表( countrycity )中选择了所有(*)数据。 Those tables have an ID fields, when I print the result there is only one ID element in array. 这些表都有一个ID字段,当我打印结果时,数组中只有一个ID元素。

The country table's fields: 国家表的字段:

  1. id; ID;
  2. name; 名称;
  3. flag; 旗;
  4. president. 主席。

The city table's fields: 城市表的字段:

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

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.

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

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