Jump to content

how to use max(id) in OOP Class?


spires

Recommended Posts

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

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";

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.