Jump to content

Archived

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

PupChow

Picking Unique ID

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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:
[code]
person
    ID
    Name
    Address
    Phone

workinfo
    ID
    personID
    Salary[/code]

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
[color=green]FROM[/color] [color=orange]person[/color] [color=green]LEFT[/color] [color=green]JOIN[/color] workinfo ON person.ID [color=orange]=[/color] workinfo.personID
[color=green]WHERE[/color] Name [color=orange]=[/color] [color=red]'Some Name'[/color] [!--sql2--][/div][!--sql3--]

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
[!--quoteo(post=355172:date=Mar 14 2006, 08:17 PM:name=PupChow)--][div class=\'quotetop\']QUOTE(PupChow @ Mar 14 2006, 08:17 PM) [snapback]355172[/snapback][/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.

Share this post


Link to post
Share on other sites
[!--quoteo(post=355175:date=Mar 14 2006, 08:22 PM:name=hitman6003)--][div class=\'quotetop\']QUOTE(hitman6003 @ Mar 14 2006, 08:22 PM) [snapback]355175[/snapback][/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.

Share this post


Link to post
Share on other sites
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.

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.