Codeigniter - value in subquery is ignored
Don't know where I went wrong with my request, but the dateread value is being ignored and I get
error Message: Undefined property: stdClass :: $ dateread.
SELECT `id`.`id`, `id`.`name`, `id`.`deleted`, `id`.`filepath`, `id`.`createddate`, (SELECT createddate as dateread FROM documents_users iu WHERE id.id = iu.docs_id AND iu.users_id = 2346)
FROM (`documents` AS id)
JOIN `documents_years` AS iy ON `id`.`id` = `iy`.`docs_id`
Can anyone please help?
+3
source to share
1 answer
Just update your query and then retrieve the value $dateread
, you need to define dateread
after your sub_query completes, not in sub_query, otherwise it will be like
(SELECT createddate FROM documents_users iu WHERE id.id = iu.docs_id AND iu.users_id = 2346)
SELECT `id`.`id`, `id`.`name`, `id`.`deleted`, `id`.`filepath`, `id`.`createddate`,
(SELECT createddate FROM documents_users iu WHERE id.id = iu.docs_id AND iu.users_id = 2346) as dateread
FROM (`documents` AS id)
JOIN `documents_years` AS iy ON `id`.`id` = `iy`.`docs_id`
+1
source to share