Jump to content

Archived

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

suckablesausage

generating a unique ID in mysql table

Recommended Posts

[code]mysql_query("CREATE TABLE IF NOT EXISTS `tablename` (`id` int(11) not null auto_increment, `field1` text(80) not null, `field2` text(80) not null, primary key (id))") or die(mysql_error());[/code]

The id field will be incremented automatically so it will be unique. If you use phpMyAdmin or something of that nature you can set all of these things while creating the table through the user interface.

Share this post


Link to post
Share on other sites
[!--quoteo(post=360191:date=Mar 30 2006, 03:07 PM:name=jireh)--][div class=\'quotetop\']QUOTE(jireh @ Mar 30 2006, 03:07 PM) [snapback]360191[/snapback][/div][div class=\'quotemain\'][!--quotec--]
hello gurus =)

i was wondering how to generate a unique ID so it can be put in mysql.
am i making sense?
[/quote]
oh oh I think I can answer this one for ya! (Im new myself). If you mean you want a unique number for lets say a user name I use the Auto-Increment.

Michelle

Share this post


Link to post
Share on other sites
ah yes i got it to work! man youre so smart =P i have another quick question. the id is 2 ,3 ,4 but is there a way to make it 00002, 00003, 00004? =)

Share this post


Link to post
Share on other sites
Define the id as

[code]id int(5) zerofill not null auto_increment[/code]

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.