gpt4 book ai didi

php - 如何解决我的代码点火器查询中的错误 1054

转载 作者:太空宇宙 更新时间:2023-11-03 11:42:46 24 4
gpt4 key购买 nike

我托管了一个代码启动器项目 here但我有错误号:1054网站最受欢迎部分显示的“on 子句”中的未知列“p.id”。

下面是给出此错误的 sql 查询。

public function get_popular()
{
// Using active records
$this->db->select('P.*, COUNT(O.product_id) as total');
$this->db->from('orders AS O');
$this->db->join('products AS P', 'O.product_id = p.id','INNER');
$this->db->group_by('O.product_id');
$this->db->order_by('total','desc');
$query = $this->db->get();
return $query->result();
}

用这行代码解决问题

$this->db->join('products AS P', 'O.product_id = p.id','INNER');

项目在我的本地机器上正常运行,直到我在这里托管它以供查看

最佳答案

这个很简单。您将表的别名声明为 P - 大写字母:

$this->db->join('products AS P', ...)

然后通过小写字母引用它:p.id

在 Windows 上,字母的大小写 - Pp - 无关紧要,在 Linux 上(您的主机可能使用它)则有关系。因此,要修复此错误,只需键入:

$this->db->join('products AS p', 'O.product_id = p.id','INNER');

将来您最好对表和字段使用严格的小写名称,因为这适用于任何操作系统。

关于php - 如何解决我的代码点火器查询中的错误 1054,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40576276/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com