spires Posted January 6, 2011 Share Posted January 6, 2011 Hi I can't seem to return the MAX position of my data in the MYSQL database. Class public static function find_last_pos(){ global $database; $sql = "SELECT max(position) as max_position FROM ".self::$table_name." LIMIT 1"; $result_array = self::find_by_sql($sql); return $result_array[0]->max_position; } HTML $POS = Blog_categories::find_last_pos(); echo $POS; Where am I going wrong? *note, the class works fine if I select * rather than max() Thanks Quote Link to comment Share on other sites More sharing options...
Simmo Posted January 6, 2011 Share Posted January 6, 2011 Hi I do something similar when I want just the one record but use this line: return !empty($result_array) ? array_shift($result_array) : false; Quote Link to comment Share on other sites More sharing options...
spires Posted January 6, 2011 Author Share Posted January 6, 2011 Yeah, I tried that first. Does not work either. Thanks, any other ideas? Quote Link to comment Share on other sites More sharing options...
beegro Posted January 6, 2011 Share Posted January 6, 2011 What version of MySQL are you using? Quote Link to comment Share on other sites More sharing options...
spires Posted January 6, 2011 Author Share Posted January 6, 2011 Server version: 5.0.51a-3ubuntu5.4 Quote Link to comment Share on other sites More sharing options...
beegro Posted January 6, 2011 Share Posted January 6, 2011 I think this may be an issue with the first implementation of MAX in MySQL 5. See: http://bugs.mysql.com/bug.php?id=36300 Of course, you could always rewrite the query like this: $sql = "SELECT position FROM ".self::$table_name." ORDER BY position ASC LIMIT 1"; Quote Link to comment Share on other sites More sharing options...
Anti-Moronic Posted January 6, 2011 Share Posted January 6, 2011 This isn't OOP. You're using static classes is all. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.