FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


AUTO INCREMENT VALUE





Relentless
Hi, I am making a website membership database.

I know how to make an auto increment on the SQL side.

But I want each member to have a unique 4 digit code starting from 0001 - 9999.

How can I make this possible?
And to prevent duplicate numbers on the database and I will use this as a username type field.

so sql layout

id - 1
number - 0001
name - Dan
pass - fsdadfasfsaf

id - 2
number - 0002
name - Dan
pass - fsdadfasfsaf

It doesn't have to be accurate meaning, doesn't matter if the id doesn't match the number. Just can't have duplicates.

EDIT:
P.S I hope I don't have to format/pad the number on output but if that's the only way then can someone please post a decent output script. But there must be a decent input script? even if, I make another table with 9999 ID's already made and the input script takes the next available one and deletes it from that database. If that makes sense.

Thanks
Dan.
Relentless
It's okay guys! I have solved it!

The answer was staring me right in the face! I guess all I needed was a cup of coffee lol

If anyone want to know how I did feel free to ask. Very Happy
SonLight
Since you posted it, and we spent the time to read it, yeah ... I think that those of us who read thru to the end would rather have more info than not, although not all details need be given.

I may not have understood the issue. You wanted unique keys, and auto-increment will insure that. On the other hand, auto-increment may not guarantee that all numbers 1 to n are used. Surely not all of them will be used if any rows are deleted, but it isn't likely you would require it in that case. if you did, you would have to re-assign all the numbers each time a row was deleted.

I guess maybe your issue was having the leading zeros show up with the small numbers. My first suggestion for that is, would it be ok if the numbers started at 1000? I think there's a way to start an auto-increment key at a fixed number, but if not, you could probably insert and delete 1000 records before you begin entering the users.

Incidentally, I hope you intend to change the format from the example, so that the password will be stored hashed and with salt.
Relentless
Okay I have not tried it yet but a friend has informed me that it may not work....

I was going to set up 2 tables.

1 pre-filled table called cards with say 1000 entry's containing:

ID , CARD_NUMBER
1 , 0001
to
1000 , 1000

Then another table with

ID(auto_inc) , fname, lname, address, email, password etc ....

I was hoping that when a user was assigned a new auto inc for example 56 when I made the php script to display user 56's information I would also call card number 56 from table 2.

In theory this should work. Or should I consider using 1 table and padding the output from another auto inc?
jcreus
Relentless wrote:
Okay I have not tried it yet but a friend has informed me that it may not work....

I was going to set up 2 tables.

1 pre-filled table called cards with say 1000 entry's containing:

ID , CARD_NUMBER
1 , 0001
to
1000 , 1000

Then another table with

ID(auto_inc) , fname, lname, address, email, password etc ....

I was hoping that when a user was assigned a new auto inc for example 56 when I made the php script to display user 56's information I would also call card number 56 from table 2.

In theory this should work. Or should I consider using 1 table and padding the output from another auto inc?

Can't the padding be added later on in PHP? Maybe that way it's simpler, isn't it?

At least in python "%04d" would work (i believe, not sure).
Related topics
[PhP] News Posting Tutorial (code, actually ^^')
What is useful way in this php+mysql problem?
Przenoszenie phpBB by przemo... tez tak mieliscie
How to create online form submission using phpmyadmin Sql
what is dump?
mySQL Query/PHP code - get the highest value...
Export and Import Mysql Table
Ajuda!!!HElp
how to simplify these codes?
SQL problem!!!
AUTO INCREMENT howto
Strange Problem in PHP-MYSQL
Help me writing this query. Urgent
SQL help.
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.