Help building this query using AR - 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: Help building this query using AR (/showthread.php?tid=54274) |
Help building this query using AR - El Forum - 08-31-2012 [eluser]ReyPM[/eluser] Hi, coders. I'm running a little problem here and can't find the solution. I'm building a query using Active Record from CI. This is the code for the query: Code: $this->db->select("u.id AS user_id, u.email, p.display_name, p.first_name, p.last_name, s.status_id, s.message, DATE_FORMAT(s.created_at, %d %d %Y %h %i %p) AS created_at"); Quote:Unknown column '%d' in 'field list' Does any know where I can use DATE_FORMAT within this query? Cheers and thanks in advance Help building this query using AR - El Forum - 08-31-2012 [eluser]Massaki[/eluser] DATE_FORMAT(s.created_at, '%d %m %Y %h %i %p') <= Put simple quotes before %d and after %p Help building this query using AR - El Forum - 08-31-2012 [eluser]michalsn[/eluser] Code: $this->db->select("u.id AS user_id, u.email, p.display_name, p.first_name, p.last_name, s.status_id, s.message, DATE_FORMAT(s.created_at, '%d %d %Y %h %i %p') AS created_at", FALSE); Help building this query using AR - El Forum - 08-31-2012 [eluser]ReyPM[/eluser] Ok, thanks both of yours, I've change a bit the code and now the query looks like: Code: $this->db->select("u.id AS user_id, u.email, p.display_name, p.first_name, p.last_name, s.status_id, s.message"); But now get this error: Quote:Error Number: 1054 The funny is the same query write as pure SQL works Cheers and thanks in advance, so what's wrong here? Help building this query using AR - El Forum - 08-31-2012 [eluser]Massaki[/eluser] Maybe it's because you have used a crasis, instead simple quote ` <- this is a crasis ' <- and this is a simple quote Help building this query using AR - El Forum - 08-31-2012 [eluser]ReyPM[/eluser] Didn't work either: Quote:You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '%d/%m/%Y a las %h:%i %p’) AS created_at FROM (`default_status` s, `default_sta' at line 1 |