PupChow Posted March 15, 2006 Share Posted March 15, 2006 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? Quote Link to comment Share on other sites More sharing options...
hitman6003 Posted March 15, 2006 Share Posted March 15, 2006 Why were you told not to use auto-increment? Quote Link to comment Share on other sites More sharing options...
PupChow Posted March 15, 2006 Author Share Posted March 15, 2006 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, PhoneTable2: ID, SalaryAnd I am in the process of building PHP pages that will allow users to enter their own information and be put into the database. Quote Link to comment Share on other sites More sharing options...
hitman6003 Posted March 15, 2006 Share Posted March 15, 2006 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 Phoneworkinfo 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--] Quote Link to comment Share on other sites More sharing options...
PupChow Posted March 15, 2006 Author Share Posted March 15, 2006 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? Quote Link to comment Share on other sites More sharing options...
hitman6003 Posted March 15, 2006 Share Posted March 15, 2006 [!--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. Quote Link to comment Share on other sites More sharing options...
PupChow Posted March 15, 2006 Author Share Posted March 15, 2006 [!--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. Quote Link to comment Share on other sites More sharing options...
keeB Posted March 15, 2006 Share Posted March 15, 2006 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.