mrjonnytou Posted July 9, 2008 Share Posted July 9, 2008 I would like to sort the result from the following query in descending order: //$sort is a the name of a table to sort by public function sortActiveByColumn($sort) { $select = $this->select()->from($this) ->where('completed LIKE ?', 0) ->order($sort); return $this->fetchAll($select); } I've tried: ->order('$sort, DESC'); ---------------------------- ->order($sort) ->desc; ---------------------------- ...and other variations. Any guidance would be helpful/appreciated as I'm not sure of the syntax. Regards, Link to comment https://forums.phpfreaks.com/topic/113910-solved-simple-query-help/ Share on other sites More sharing options...
jesushax Posted July 9, 2008 Share Posted July 9, 2008 try ORDER BY $sort DESC Link to comment https://forums.phpfreaks.com/topic/113910-solved-simple-query-help/#findComment-585337 Share on other sites More sharing options...
mrjonnytou Posted July 9, 2008 Author Share Posted July 9, 2008 no go. As soon as I do that, I get a syntax error: (Unexpexted T_String) Link to comment https://forums.phpfreaks.com/topic/113910-solved-simple-query-help/#findComment-585350 Share on other sites More sharing options...
revraz Posted July 9, 2008 Share Posted July 9, 2008 Let's see that change. no go. As soon as I do that, I get a syntax error: (Unexpexted T_String) Link to comment https://forums.phpfreaks.com/topic/113910-solved-simple-query-help/#findComment-585351 Share on other sites More sharing options...
mrjonnytou Posted July 9, 2008 Author Share Posted July 9, 2008 public function sortActiveByColumn($sort) { $select = $this->select()->from($this) ->where('completed LIKE ?', 0) ->order by $sort DESC; return $this->fetchAll($select); } Link to comment https://forums.phpfreaks.com/topic/113910-solved-simple-query-help/#findComment-585353 Share on other sites More sharing options...
mrjonnytou Posted July 9, 2008 Author Share Posted July 9, 2008 anyone...? Link to comment https://forums.phpfreaks.com/topic/113910-solved-simple-query-help/#findComment-585386 Share on other sites More sharing options...
mrjonnytou Posted July 9, 2008 Author Share Posted July 9, 2008 the code works fine when you replace the $sort with a string value but there seems to be a problem with $sort when it is enclosed within ' '. I.e. $sort isn't being recognised as a variable. Link to comment https://forums.phpfreaks.com/topic/113910-solved-simple-query-help/#findComment-585397 Share on other sites More sharing options...
revraz Posted July 9, 2008 Share Posted July 9, 2008 You can't enclose a variable in single quotes, did you try double quotes? Link to comment https://forums.phpfreaks.com/topic/113910-solved-simple-query-help/#findComment-585419 Share on other sites More sharing options...
mrjonnytou Posted July 9, 2008 Author Share Posted July 9, 2008 It Works! Thanks a lot. I can't believe thats all it was. Much appreciated. The working code: public function sortActiveByColumn($sort) { $select = $this->select()->from($this) ->where('completed LIKE ?', 0) ->order("$sort desc"); return $this->fetchAll($select); } Regards, Link to comment https://forums.phpfreaks.com/topic/113910-solved-simple-query-help/#findComment-585423 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.