Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

auto increment varchar !

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

auto increment varchar !

Postby wckf » Thu Apr 04, 2013 2:41 pm

ideas anyone ?
wckf
New php-forum User
New php-forum User
 
Posts: 15
Joined: Wed Mar 27, 2013 7:59 am

Re: auto increment varchar !

Postby johnj » Thu Apr 04, 2013 8:24 pm

Better to split that varchar field into two separate fields, one of varchar to keep the character part and the other should be integer or numeric on which you can enable auto increment.
e.g. field_1 will be 'C' and field_2 will be 1,or 2, or 3 etc. When you display you can concatenate both as C1 or C2 etc

The other option will be to increment the field on the application side and just save it to the varchar field in the database.e.g. if the original value was C001 in the table, increment it to C002 and save it so that the new field value will be C002.
johnj
php-forum Super User
php-forum Super User
 
Posts: 1805
Joined: Thu Mar 10, 2011 5:07 pm

Re: auto increment varchar !

Postby seandisanti » Fri Apr 05, 2013 1:36 am

You can also set an insert trigger, as said in your other thread, so that it''s automatically done for you whenever a row is inserted. here's an example so you see how easy it is. http://dev.mysql.com/doc/refman/5.0/en/ ... yntax.html
seandisanti
php-forum Fan User
php-forum Fan User
 
Posts: 838
Joined: Mon Oct 01, 2012 12:32 pm


Return to PHP coding => General

Who is online

Users browsing this forum: Bing [Bot] and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron