Finding the MySQL MAX number in Joomla Database

I needed to find the max number in my Joomla Database and increment this by one. Here is the code I used that ended up working for me.

// Get the highest ticket number and add 1
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select(‘MAX(‘.$db->quoteName(‘number’).’)’)
->from($db->quoteName(‘ticket_num’))
->order(‘number ASC’)
->limit(‘1’);
$db->setQuery($query);
$my_value = $db->loadResult();
// Add 1
$next_num = ($my_value + 1);

I found this link that helped me figure it out.

http://stackoverflow.com/questions/21280886/mysql-max-function-does-not-work-in-joomla

I hope this helps someone else…

This entry was posted in Uncategorized. Bookmark the permalink.

One Response to Finding the MySQL MAX number in Joomla Database

  1. Roberto says:

    Thank you

Leave a Reply

Your email address will not be published. Required fields are marked *