Codeigniter:订单子句中的列“id"不明确

Codeigniter:订单子句中的列“id

问题描述:

我正在使用 CodeIgniter 的 Active Record 类,我正在使用以下代码检索错误:

I'm using CodeIgniter's Active Record Classes and I'm retrieving an error using the following code:

$this->db->select("*");
$this->db->order_by("id");
$this->db->limit($limit, $offset);
$this->db->from("atoms");
$this->db->join("atommeta", "atommeta.atom_id = atoms.atom_id");

$query  = $this->db->get();

它产生这个错误:

Error Number: 1052

Column 'id' in order clause is ambiguous

SELECT * FROM (`atoms`) JOIN `atommeta` ON `atommeta`.`atom_id` = `atoms`.`atom_id` ORDER BY `id` LIMIT 10

Filename: /Applications/MAMP/htdocs/atom/models/atom_model.php

Line Number: 197

第 197 行:$query = $this->db->get();

有什么想法吗?似乎与order_by

该错误意味着您正尝试按在多个表中使用的列名进行排序.使用包含要作为排序依据的列的表的名称更新您的 order_by 语句.例如:

The error means that you are trying to order by a column name that is used in more than one table. Update your order_by statement with the name of the table that has the column you want to order by. For example:

$this->db->order_by('atoms.id');