php - 如何在 codeigniter 数据表查询中使用 CONCAT?

标签 php mysql codeigniter datatables concatenation

我正在使用 codeigniter 框架,在此我使用数据表生成值以查看文件。我需要对此查询的 CONCAT 选项。但是当我使用它时显示 500 个内部服务器错误。下面我给出了查询。

 $this->load->library('datatables');

 $this->datatables
    ->select("sales.id as sid, CONCAT(sales.id, ' ',sales.export_status) as chid, date, reference_no, customer_name, note, delete_status, table_name, count, inv_total, inv_discount, total_tax2, total, internal_note");
 $this->datatables->join('order_table', 'order_table.id=sales.tableid', 'left');
 $this->datatables->from('sales'); 

我不知道是什么问题,我引用了很多链接,但我无法得到正确的解决方案。请指导我。提前致谢。

最佳答案

$this->db->select() 接受可选的第二个参数。如果您将它设置为 FALSE,CodeIgniter 将不会尝试使用反引号保护您的字段或表名。如果您需要复合选择语句,这很有用。

  $this->datatables->select("sales.id as sid, CONCAT(sales.id, ' ',sales.export_status) as chid, date, reference_no, customer_name, note, delete_status, table_name, count, inv_total, inv_discount, total_tax2, total, internal_note",FALSE);

关于php - 如何在 codeigniter 数据表查询中使用 CONCAT?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32398920/

相关文章:

php - 我如何在 php.ini 的日期范围内找到 mysql 表中多个日期的出现次数?

php - Mysql 存储大量位大小的设置

php - 无法用 "templating"替换别名 "fos_rest.templating"

php - 测试 Web 应用程序中的安全漏洞 : Best practices?

mysql - 提高 SQL 查询速度

php - 如何制作内嵌可编辑内容?

MySQL 子查询(或 UNION?)

php - 数据表子行中的二级记录如何显示各自id的?

mysql - where 子句中的列 'id' 不明确

php - CodeIgniter activerecord,检索最后一个插入ID?