CodeIgniter Forums
SQL Query dont work in CI - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: SQL Query dont work in CI (/showthread.php?tid=16045)



SQL Query dont work in CI - El Forum - 02-23-2009

[eluser]codeDeveloper[/eluser]
Hello,
Please, help me, why don't work this SQL query:
Code:
$this->db->query ('SELECT u.nick, f.fuin, count(o.time) as online FROM `icqdate_friends` as f JOIN `icqdate_users` as u ON u.uin=f.fuin LEFT JOIN `icqdate_online` as o ON f.fuin=o.uin and o.time > NOW() - INTERVAL 5 MINUTE WHERE f.uin=? group by f.fuin order by online', array(723640));
$q = $this->db->get();
return $q->result();

CodeIgniter writing:
Quote:A Database Error Occurred

Error Number: 1096

No tables used

SELECT *

P.S. If helping to rewrite the query to Active Record would be very grateful


SQL Query dont work in CI - El Forum - 02-23-2009

[eluser]pistolPete[/eluser]
If you use query(), you must not use get() as well!
Have a look at the userguide: http://ellislab.com/codeigniter/user-guide/database/queries.html


SQL Query dont work in CI - El Forum - 02-23-2009

[eluser]obiron2[/eluser]
also, you need to group by u.nick and f.fuin if you are going to select both.


SQL Query dont work in CI - El Forum - 02-23-2009

[eluser]codeDeveloper[/eluser]
Thank you, works.
And as to put into Active Record?
Suggest me?