Codeigniter:订单子句中的列“id"不明确 [英] Codeigniter: Column 'id' in order clause is ambiguous

查看:33
本文介绍了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');

这篇关于Codeigniter:订单子句中的列“id"不明确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆