Jump to content


Photo

Picking Unique ID


  • Please log in to reply
7 replies to this topic

#1 PupChow

PupChow
  • New Members
  • Pip
  • Newbie
  • 9 posts

Posted 15 March 2006 - 01:01 AM

Sorry if this is a very elementary question, but I just cannot seems to find the answer in the books I have (probably because it is very simple?) or online.

What is the best way to create a unique ID? This ID will be used to link up a couple tables, and I was adviced to not use Auto-number field. Is there a easy way to generate a unique number in PHP while it is inserting the data into the database?


#2 hitman6003

hitman6003
  • Members
  • PipPipPip
  • Advanced Member
  • 1,807 posts

Posted 15 March 2006 - 01:04 AM

Why were you told not to use auto-increment?

#3 PupChow

PupChow
  • New Members
  • Pip
  • Newbie
  • 9 posts

Posted 15 March 2006 - 01:09 AM

Something about it is hard to manage. I didn't really quite follow thought...

What I am trying to do in simple term is 2 tables:

Table1: ID, Name, Address, Phone
Table2: ID, Salary

And I am in the process of building PHP pages that will allow users to enter their own information and be put into the database.

#4 hitman6003

hitman6003
  • Members
  • PipPipPip
  • Advanced Member
  • 1,807 posts

Posted 15 March 2006 - 01:15 AM

There's nothing about it that's hard to manage...every time a record is inserted into the db, it assigns it the next incremental id.

Potential table structure:
person
    ID
    Name
    Address
    Phone

workinfo
    ID
    personID
    Salary

sample query:

[!--sql--][div class=\'sqltop\']SQL[/div][div class=\'sqlmain\'][!--sql1--][span style=\'color:blue;font-weight:bold\']SELECT[/span] Name, Address, Phone, Salary
FROM person LEFT JOIN workinfo ON person.ID = workinfo.personID
WHERE Name = 'Some Name' [!--sql2--][/div][!--sql3--]

#5 PupChow

PupChow
  • New Members
  • Pip
  • Newbie
  • 9 posts

Posted 15 March 2006 - 01:17 AM

Gotcha. Is Auto-Increment Number a pretty popular thing (or standard) to use when it comes to unique ID?

On a related note, do I also just join the table first if I want to delete a record?


#6 hitman6003

hitman6003
  • Members
  • PipPipPip
  • Advanced Member
  • 1,807 posts

Posted 15 March 2006 - 01:22 AM

[!--quoteo(post=355172:date=Mar 14 2006, 08:17 PM:name=PupChow)--][div class=\'quotetop\']QUOTE(PupChow @ Mar 14 2006, 08:17 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
do I also just join the table first if I want to delete a record?
[/quote]

No, you'll have to delete each of them.

#7 PupChow

PupChow
  • New Members
  • Pip
  • Newbie
  • 9 posts

Posted 15 March 2006 - 04:22 AM

[!--quoteo(post=355175:date=Mar 14 2006, 08:22 PM:name=hitman6003)--][div class=\'quotetop\']QUOTE(hitman6003 @ Mar 14 2006, 08:22 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
No, you'll have to delete each of them.
[/quote]

Would I need to do two different SQL queries for insert as well? Sorry, I am pretty new to this.

#8 keeB

keeB
  • Staff Alumni
  • Advanced Member
  • 1,078 posts
  • LocationCalifornia

Posted 15 March 2006 - 07:27 AM

I am quite sure you can manage with 1 SQL statement, but to be on the safe side you should definately use 2 unless you test it thoroughly.. although I really don't see why it wouldnt work with one.

Come visit my site to see my latest projects
http://nick.stinemates.org/wordpress/





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users