Byte My Data

A personal collection of advice and solutions I've used.

About the author

Something about the author

Get the next auto increment id in MySQL for Joomla articles

Here's a great little query to get the next auto increment id. It's better than grabbing the last id and incrementing it because entries may have been deleted that were added after the last id.

SELECT AUTO_INCREMENT AS id
FROM information_schema.tables
WHERE table_schema = 'mydatabase'
AND table_name = 'mytable';

Or for Joomla where I needed it:

$query = "SELECT AUTO_INCREMENT AS id FROM information_schema.tables WHERE table_schema = 'mydatabase' AND table_name = 'jos_content'";
$db->setQuery($query);
$rows = $db->loadObjectList();
$nextid = $rows[0]->id;

 


Permalink | Comments (0) | Post RSSRSS comment feed

JTableMenu::store failed - Duplicate entry '0' for key 1 SQL=INSERT INTO `jos_menu` (

If you get this it means the auto-increment isn't set for the id primary key in the table.

All you have to do is change the column to auto-increment through MySQL Administrator or phpMyAdmin and that will solve it.

In phpMyAdmin, edit the id column and set the "Extra" attribute to auto_increment.


Categories: Joomla | MySQL
Permalink | Comments (0) | Post RSSRSS comment feed