更新的代码
$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/