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 Link to comment https://forums.phpfreaks.com/topic/223597-how-to-use-maxid-in-oop-class/ 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; Link to comment https://forums.phpfreaks.com/topic/223597-how-to-use-maxid-in-oop-class/#findComment-1155778 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? Link to comment https://forums.phpfreaks.com/topic/223597-how-to-use-maxid-in-oop-class/#findComment-1155784 Share on other sites More sharing options...
beegro Posted January 6, 2011 Share Posted January 6, 2011 What version of MySQL are you using? Link to comment https://forums.phpfreaks.com/topic/223597-how-to-use-maxid-in-oop-class/#findComment-1155787 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 Link to comment https://forums.phpfreaks.com/topic/223597-how-to-use-maxid-in-oop-class/#findComment-1155788 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"; Link to comment https://forums.phpfreaks.com/topic/223597-how-to-use-maxid-in-oop-class/#findComment-1155809 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. Link to comment https://forums.phpfreaks.com/topic/223597-how-to-use-maxid-in-oop-class/#findComment-1155844 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.