Jump to content


how to generate autoincrement number using frontend


  • Please log in to reply
1 reply to this topic

#1 Guest_purnendu_*

Guest_purnendu_*
  • Guests

Posted 03 July 2006 - 06:48 AM

CREATE TABLE `category` (                   
            `catid` varchar(15) NOT NULL default '0' auto_increment, 
            `catname` varchar(50) default NULL,       
            `status` varchar(50) default NULL,         
            PRIMARY KEY  (`catid`),                   
            KEY `catid1` (`catid`),                   
            KEY `cat` (`catname`)                     
          ) TYPE=InnoDB COMMENT='InnoDB free: 3072 kB' 

I have created one table category where column catid as varchar and autoincrement, but in want to insert  record
into database as "A00001", "A00002", "A00003" like that as a autogenerated with the help of coding
into frontend.

Plz help me
Purnendu

#2 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 03 July 2006 - 06:55 AM

you can't auto_increment a varchar column type. it has to be an integer type. now what you CAN do is make a varchar and set it to be unique.  then select it, ordered by itself descending order limit 1, and use php to split the letters from the numbers to find out the next number, then build the next apha numeric string for insertion.
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users