For some reason I am getting the number or rows and not the results I need.
$sql = "SELECT t1.*,
u.id,
u.username,
p.profile_picture
FROM messages t1
JOIN (SELECT from_id, MAX(date) date FROM messages GROUP BY from_id) t2
ON t1.from_id = t2.from_id AND t1.date = t2.date
LEFT JOIN
users u
ON
u.id = t1.from_id
LEFT JOIN
profiles p
ON
p.user_id = t1.from_id
";
$query = DB::query(‘Database::SELECT’,$sql);
$messages = $query->execute();
echo Kohana::debug($messages); // for some reason getting number of rows here
The documentation says
Specifying the type changes the returned result. When using
Database::SELECT, a Database_Query_Result will be returned.
Database::INSERT queries will return the insert id and number of rows.
For all other queries, the number of affected rows is returned.
What am I doing wrong?
You need to use
$query = DB::query(Database::SELECT,$sql);.Notice the lack of quotes. You need to use the constant value.