gpt4 book ai didi

php - Codeigniter 2 多重连接和where语句

转载 作者:行者123 更新时间:2023-11-29 17:31:28 25 4
gpt4 key购买 nike

更新代码

$office = $this->session->userdata('department');

$query = "SELECT `doc`.`id`, `doc`.`barcode`, `doc`.`sub`, `doc`.`source_type`, `doc`.`sender`, `doc`.`address`, `doc`.`description`, `doc`.`receipient`, `doc`.`status`, DATE_FORMAT(`doc`.`datetime_added`, '%m/%d/%Y-%h:%i %p') as datetime_added,
(SELECT GROUP_CONCAT(`tag`) FROM `tags` WHERE `tags`.`documentId` = `doc`.`id` GROUP BY `tags`.`documentId`) as `tags`
FROM `documents` AS `doc`
JOIN `transactions` AS `trans` ON `doc`.`id` = `trans`.`document_id`
JOIN `trackers` AS `track` ON `doc`.`id` = `track`.`document_id`
WHERE `doc`.`status` = 'Processing'
AND `track`.`action` = '1')
AND `track`.`location` = '$office'
ORDER BY `doc`.`id` DESC";
$go = $this->db->query($query)->result_array();
var_dump($go); exit();

我试图完成的任务是显示我们办公室中正在处理且具有操作1的所有文档。文档可能带有备忘录、请求、财务等标签。输出不正确,未显示我们办公室中的所有记录。我认为 WHERE 子句有问题?我的代码中的罪魁祸首是什么?

最佳答案

通过删除 1 周围的单引号来更新您的查询:

$query = "SELECT `doc`.`id`, `doc`.`barcode`, `doc`.`sub`, `doc`.`source_type`, `doc`.`sender`, `doc`.`address`, `doc`.`description`, `doc`.`receipient`, `doc`.`status`, DATE_FORMAT(`doc`.`datetime_added`, '%m/%d/%Y-%h:%i %p') as datetime_added,
(SELECT GROUP_CONCAT(`tag`) FROM `tags` WHERE `tags`.`documentId` = `doc`.`id` GROUP BY `tags`.`documentId`) as `tags`
FROM `documents` AS `doc`
JOIN `transactions` AS `trans` ON `doc`.`id` = `trans`.`document_id`
JOIN `trackers` AS `track` ON `doc`.`id` = `track`.`document_id`
WHERE `doc`.`status` = 'Processing'
**AND `track`.`action` = 1)**
AND `track`.`location` = '$office'
ORDER BY `doc`.`id` DESC";

关于php - Codeigniter 2 多重连接和where语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50595506/

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