从两个表的同名两列中获取数据
Fetch data from same named two columns of two tables
我正在尝试使用连接查询从 2 table 秒中获取数据。在这里,我在 2 table 中有 2 列具有相同的列名。
这是我的查询:
public function get_all_expenses()
{
$this->db->select("*",'category.name as cat_name');
$this->db->from('expense');
$this->db->join('category','expense.cat_id = category.id');
$this->db->join('users','expense.user_id = users.id');
$query = $this->db->get();
return $query;
}
我可以获取 1 table 的 1 列的数据。但是我无法获取另一个 table 的另一列的数据。我正在使用 CodeIgniter。
根据 CodeIgniter 文档,数据库 select
方法接受单个参数。 select 的正确语法是:
$this->db->select('*, category.name as cat_name');
我正在尝试使用连接查询从 2 table 秒中获取数据。在这里,我在 2 table 中有 2 列具有相同的列名。
这是我的查询:
public function get_all_expenses()
{
$this->db->select("*",'category.name as cat_name');
$this->db->from('expense');
$this->db->join('category','expense.cat_id = category.id');
$this->db->join('users','expense.user_id = users.id');
$query = $this->db->get();
return $query;
}
我可以获取 1 table 的 1 列的数据。但是我无法获取另一个 table 的另一列的数据。我正在使用 CodeIgniter。
根据 CodeIgniter 文档,数据库 select
方法接受单个参数。 select 的正确语法是:
$this->db->select('*, category.name as cat_name');