【问题标题】:Concat 2 column in one using codeigniter使用 codeigniter 将 2 列合二为一
【发布时间】:2020-01-27 16:29:58
【问题描述】:

我想在我的查询中将名字和姓氏连接为全名。

$query = $this->db->select('CONCAT(w.firstName," ",w.lastName) as fullName,w.ID,w.firstName,w.lastName, w.firstname_ar, w.lastname_ar, w.cin , w.tel, w.tel2, w.poste_id, w.gender, w.date_birth, w.address, w.address_ar, w.familySituation, w.socialSecurity, w.typeContract, w.period,w.email,w.status,r.name,w.conge as cng,w.startDateContract, w.pictureProfile, w.endDateContract, w.dateTitulation, w.rib, w.languages, w.passport, w.passport_end_date, w.urgent_phone, w.urgent_phone_name,w.pointage_id as idpointeur, w.shift_start as heure_arr, w.shift_end as heure_dep, w.worker_role as workerRole, r.color as roleColor, r.name as departement, conge_annee, c.name as companyName, c.logo as logoCompany, p.title as poste',FALSE)->from('Workeforce w')->join('Role r', 'r.ID = w.RoleID')->join('Company c', 'c.ID = w.CompanyID')->join('poste p', 'p.id = w.poste_id', 'left')->where('w.worker_role <', 100);

它给了我这个错误。

致命错误:未捕获异常:SQLSTATE[42S22]:未找到列: 1054 未知列 'CONCAT(w.firstName' in 'field list' in /Users/mac/www/application/core/models/workeforce_model.php:100 堆栈 追踪:#0

【问题讨论】:

    标签: php sql codeigniter


    【解决方案1】:

    尝试转义 CONCAT 中的引号。
    您的错误表明“'CONCAT(w.firstName'”不是有效列这一事实向我表明,您的数据库认为 SELECT 在那里结束。

    CONCAT(w.firstName,\" \",w.lastName) as fullName, ....
    

    在引号前添加 \ 将使其转义。
    您可以在此处阅读有关转义特殊字符的更多信息: https://dev.mysql.com/doc/refman/8.0/en/string-literals.html

    【讨论】:

      猜你喜欢
      • 2011-07-17
      • 1970-01-01
      • 2022-01-09
      • 1970-01-01
      • 2021-06-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-08-19
      相关资源
      最近更新 更多