Jump to content


Add a id automatically


5 replies to this topic

#1 Crofty

    Young Padawan

  • Members
  • Pip
  • 32 posts

Posted 30 August 2006 - 05:30 AM

hey, just wondering if anyone could help me. i have no idea how to do this so i come to the experts once again lol.

i am trying to add a unique id to a row in mysql database when i insert a new product.

i could add one manually but i would rather let the computer do it for example i am looking for a script that looks at the last id on the above row then add 1 to it so its gives me the id if you see what i mean

thanks

#2 Av-

    I Feel Left Out

  • Members
  • PipPipPipPip
  • 1,971 posts
  • Gender:Male
  • Location:10 ft. below sea level

Posted 30 August 2006 - 06:08 AM

add auto_increment to the specific field.

http://dev.mysql.com/doc/refman/5.0/en/rep...-increment.html

#3 Matthew.

    Official Spammer .Matt

  • Members
  • PipPipPipPip
  • 2,749 posts
  • Gender:Male
  • Location:England

Posted 30 August 2006 - 07:53 AM

Just make sure the field type is tinyint and not int, common mistake :)

Just make sure the field type is INT and not TINYINT, common mistake :D

Edited by .Matt, 30 August 2006 - 09:03 AM.


#4 Hayden

    P2L Jedi

  • Members
  • PipPipPip
  • 716 posts
  • Gender:Male
  • Location:Texas

Posted 30 August 2006 - 08:48 AM

View Post.Matt, on Aug 30 2006, 07:53 AM, said:

Just make sure the field type is tinyint and not int, common mistake :)


curious Matt, why is that?

Quote

TINYINT[Length]
1 byte
Range of -128 to 127 or 0 to 255 unsigned.

SMALLINT[Length]
2 bytes
Range of -32,768 to 32,767 or 0 to 65535 unsigned.

MEDIUMINT[Length]
3 bytes
Range of -8,388,608 to 8,388,607 or 0 to 16,777,215 unsigned.

INT[Length]
4 bytes
Range of -2,147,483,648 to 2,147,483,647 or 0 to 4,294,967,295 unsigned.


#5 Matthew.

    Official Spammer .Matt

  • Members
  • PipPipPipPip
  • 2,749 posts
  • Gender:Male
  • Location:England

Posted 30 August 2006 - 08:59 AM

lol, ahha i meant INT not TINYINT as TINYINT has a 127 entry limit, which means you will get an error after 127 records.

Thats what i meant above. I blame lack of sleep rofl.

edit: just remembered your pm.

Edited by .Matt, 30 August 2006 - 09:02 AM.


#6 Hayden

    P2L Jedi

  • Members
  • PipPipPip
  • 716 posts
  • Gender:Male
  • Location:Texas

Posted 30 August 2006 - 01:32 PM

View Post.Matt, on Aug 30 2006, 08:59 AM, said:

lol, ahha i meant INT not TINYINT as TINYINT has a 127 entry limit, which means you will get an error after 127 records.

Thats what i meant above. I blame lack of sleep rofl.

edit: just remembered your pm.


lol. i thought you had an actual answer to that. :P





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users