Jump to content

how to generate autoincrement number using frontend


Guest purnendu

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

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.