Forum Moderators: coopster

Message Too Old, No Replies

How to generate and insert serial no

how to generate and insert serial no

         

dongan

4:45 pm on May 17, 2007 (gmt 0)

10+ Year Member



Hi,

table name: serial

ID (int 8 primary key)
SerialNo (int 8 not null)

The serial no should be 12000001 (12 is always default. 1 is the ID of the record and remaining will be filled with 0. In total it should be 8 digits)

now, say the first record should be

1 - 12000001
2 - 12000002
3 - 12000003
....
15 - 12000015
.....
200 - 12000200
....
10001 - 12001001

Can anyone tell me what is the mysql query and php code?

Any help is greatly appreciated.

Thanks.

Regards,
Dongan

mcibor

4:55 pm on May 17, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Tell me, do you really require it to be stored in the db? And is it always the same as id?

If you perform this little trick it will do what you want

TABLE `serial`
id INT NOT NULL auto_increment
no serial number in mysql

then in query:

SELECT ID, 12000000 + ID AS SerialNo FROM serial;

and voile

Hope this helps.
Michal