db->get('community_messages t1', 1);" SELECT t1...." /> db->get('community_messages t1', 1);" SELECT t1...." /> db->get('community_messages t1', 1);" SELECT t1...."/>

Unknown column in 'where clause' | with where or & joins

181 views Asked by At

Error Number: 1054 Unknown column 'FI_t1.messageID' in 'on clause'
Line Number: 102
"$query = $this->db->get('community_messages t1', 1);"

SELECT t1.*, t2.toUserID, max(unread) as unread, parentID, deleted, FI_users.userID, email, firstName, lastName, displayName, avatar FROMFI_community_messagest1JOINFI_community_messagemapt2ONt2.messageID=FI_t1.messageIDJOINFI_usersONFI_users.userID=FI_t1.userIDWHERE t1.siteID = 1 AND deleted = 0 AND (t2.toUserID = 3 OR t2.userID = 3) GROUP BYmessageIDLIMIT 1

-

So the function in question is this(https://pastebin.com/haG1ybF7)

Note this was working fine on CodeIgniter 2 encountered this a lot and what seemed to make it work was specifying the from and limit after the select, also ordering the get and join.

So changed the function to this(https://pastebin.com/MeH5aBKH).

Although this works totally fine, I can't help but feel there's a better way of doing this that would make it more readable and easy to understand. This is important as it's on an opensource project for others to use too.

Kind regards.

0

There are 0 answers