gpt4 book ai didi

php - CI 中的多个选择语句

转载 作者:行者123 更新时间:2023-11-30 22:17:16 25 4
gpt4 key购买 nike

我有这行代码,

$val = self::$db->select('*')->select('a.id')->select("CONCAT(user_profile.firstname,' ',user_profile.middlename,' ',user_profile.lastname) AS user_name")->from('a')->join('user_profile', 'po.user_id = user_profile.id')->get()->result();

在此查询中,它将选择行中的所有数据。有一列被选中,“modified_by”。我想用它来获取相应的 user_profile.firstname。

我试过这行代码但没有用,

$val = self::$db->select('*')->select('a.id')->select('a.modified_by' as modifier)->select("CONCAT(user_profile.firstname,' ',user_profile.middlename,' ',user_profile.lastname) AS user_name")->select('user_profile.firstname where user_profile.id = modifier ')->from('a')->join('user_profile', 'po.user_id = user_profile.id')->get()->result();

最佳答案

为了进一步@Keeleon 的评论,您可以使用逗号组合 SELECT 语句,这样您上面的代码是完全合法的:

$this->db->select('*, a.id, a.modified_by 作为修饰符, CONCAT(user_profile.firstname,' ',user_profile.middlename,' ',user_profile.lastname) AS user_name )-> .... ->get()

虽然看起来您正在执行子查询,但在使用 codeigniter 的默认函数时会变得很棘手 - 您可以使用此答案作为解决问题的方法:https://stackoverflow.com/a/16303021/3629438

但它的要点是在组合查询之前将它们分开。

关于php - CI 中的多个选择语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37861996/

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