Jump to content

Archived

This topic is now archived and is closed to further replies.

Guest purnendu

how to generate autoincrement number using frontend

Recommended Posts

Guest purnendu
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

×

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.