Jump to content

how to use max(id) in OOP Class?


spires

Recommended Posts

Hi

I am trying to set this simple bit of code up in a class:

$lastID_sql = "SELECT max(id) FROM admin_interest";
$lastID_query = mysql_query($lastID_sql) or die ('Line 6: '.mysql_error());
$lastID_Row = mysql_fetch_array($lastID_query);
$lastID = $lastID_Row['max(id)'];

 

As you can see, you need to return the max(id) to be able to display that value that you want.

 

 

My Class:

class Admin_interest {

protected static $table_name="admin_interest";
protected static $db_fields = array('id', 'interest_category', 'type');
public $id;
public $interest_category;
public $type;

public static function find_by_maxID(){
	global $database;
	$sql = "SELECT max(id) FROM ".self::$table_name." LIMIT 1";
	$result_array = self::find_by_sql($sql);
	return !empty($result_array) ? array_shift($result_array) : false;
}

 

Displaying the class

$found_lastID = Admin_interest::find_by_maxID();
echo $found_lastID->id . '<br>';

 

 

The value, as expected is blank.

I've tried $found_lastID->max(id)

But this comes back with an error

 

 

Any ideas?

 

Thanks :)

Link to comment
https://forums.phpfreaks.com/topic/212691-how-to-use-maxid-in-oop-class/
Share on other sites

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.