Lamez Posted July 10, 2008 Share Posted July 10, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/114176-solved-cms-system-need-help/ Share on other sites More sharing options...
PFMaBiSmAd Posted July 10, 2008 Share Posted July 10, 2008 Use an auto_increment index column to get the database to do this for you. Quote Link to comment https://forums.phpfreaks.com/topic/114176-solved-cms-system-need-help/#findComment-587053 Share on other sites More sharing options...
Lamez Posted July 10, 2008 Author Share Posted July 10, 2008 I am not familiar with that, is that a PHP function? Quote Link to comment https://forums.phpfreaks.com/topic/114176-solved-cms-system-need-help/#findComment-587054 Share on other sites More sharing options...
spider661 Posted July 10, 2008 Share Posted July 10, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/114176-solved-cms-system-need-help/#findComment-587063 Share on other sites More sharing options...
Lamez Posted July 10, 2008 Author Share Posted July 10, 2008 so now I can just insert? like this: <?php $q = "INSERT INTO `home` (id, content, title) VALUES ('$id', '$content', '$title')"; mysql_query($q); ?> wait, I am confused. Would that be right (above). Quote Link to comment https://forums.phpfreaks.com/topic/114176-solved-cms-system-need-help/#findComment-587067 Share on other sites More sharing options...
Lamez Posted July 10, 2008 Author Share Posted July 10, 2008 oh, and I just set the database to auto_increment Quote Link to comment https://forums.phpfreaks.com/topic/114176-solved-cms-system-need-help/#findComment-587070 Share on other sites More sharing options...
spider661 Posted July 10, 2008 Share Posted July 10, 2008 <?php $q = "INSERT INTO `home` (content, title) VALUES ('$content', '$title')"; mysql_query($q); ?> will do it you dont have to put in an id now the database will do it auto for you. Quote Link to comment https://forums.phpfreaks.com/topic/114176-solved-cms-system-need-help/#findComment-587073 Share on other sites More sharing options...
Lamez Posted July 10, 2008 Author Share Posted July 10, 2008 aww that is so easy thanks very much Quote Link to comment https://forums.phpfreaks.com/topic/114176-solved-cms-system-need-help/#findComment-587074 Share on other sites More sharing options...
spider661 Posted July 10, 2008 Share Posted July 10, 2008 jsut trying to do my part to help your welcome Quote Link to comment https://forums.phpfreaks.com/topic/114176-solved-cms-system-need-help/#findComment-587078 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.