Jump to content

Recommended Posts

 

How would I be able to pull the highest ID number from the database and add 1 to it?

 

example:

 

--ID-- --title-- --news--

1          wel..    welcome to the website

2          hi          this is an update

..        ..          ..

11        hello      look at this

 

so I would want to select the ID 11 and add 1 to it so it would become 12, and then I could insert it into the database.

 

Thanks Guys :D

 

Link to comment
https://forums.phpfreaks.com/topic/114176-solved-cms-system-need-help/
Share on other sites

is a database function built into them i use mysql myself. go into the property's of the table and set id or the one you want to go up to auto_increment and then when you add your line just leave id blank and the database will put the next highest number in there for you.

 

or when you build the table set it here is how i built a table i used.

 

CREATE TABLE `server_globals` (
  `id` int(11) NOT NULL auto_increment,
  `name` varchar(65) NOT NULL default '',
  `value` varchar(65) NOT NULL default '?',
  PRIMARY KEY  (`id`),
  UNIQUE KEY `qname` (`name`,`value`)
) ENGINE=MyISAM AUTO_INCREMENT=1280 DEFAULT CHARSET=latin1;

 

see how i set id to auto_increment and even set a starting value

 

so UPDATE tablename SET `id` int(11) NOT NULL auto_increment

 

should work

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.