Jump to content


Photo

generating a unique ID in mysql table


  • Please log in to reply
5 replies to this topic

#1 suckablesausage

suckablesausage
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 30 March 2006 - 11:07 PM

hello gurus =)

i was wondering how to generate a unique ID so it can be put in mysql.
am i making sense?

#2 txmedic03

txmedic03
  • Members
  • PipPipPip
  • Advanced Member
  • 313 posts
  • LocationCall, TX, USA

Posted 30 March 2006 - 11:31 PM

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());

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.

SEMPER FIDELIS!

I can't stop you from doing something silly, but at least I can help you do it right.


#3 Plazman65

Plazman65
  • Members
  • PipPipPip
  • Advanced Member
  • 46 posts

Posted 30 March 2006 - 11:33 PM

[!--quoteo(post=360191:date=Mar 30 2006, 03:07 PM:name=jireh)--][div class=\'quotetop\']QUOTE(jireh @ Mar 30 2006, 03:07 PM) View Post[/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


#4 suckablesausage

suckablesausage
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 30 March 2006 - 11:55 PM

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? =)

#5 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 31 March 2006 - 01:04 AM

Define the id as

id int(5) zerofill not null auto_increment

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#6 suckablesausage

suckablesausage
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 31 March 2006 - 09:04 AM

wow!! thank you!! gosh i love this forum :)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users