pioneerx01 Posted December 12, 2009 Share Posted December 12, 2009 Hello, I have a problem that I can not solve. For ease of communication lets say that I have a registration from where people fill out their first mane and hit submit (lets say John is filling out the form). Once submitted the data travels to my database where new record is created, John is put under "name1" column, as well as ID that is unique to each record. How do I set the database in such manner that it combined those two columns into one (a third one, like "name2") so the end result is something like John32? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/184858-associating-field-and-id-in-database/ Share on other sites More sharing options...
ngreenwood6 Posted December 12, 2009 Share Posted December 12, 2009 something like this: //some name here $name1 = 'something'; //just insert the first name for now $query = mysql_query("INSERT INTO table(name1) VALUES ('$name1')"); //gets the last id $last_id = mysql_insert_id(); //once we have the id and the record there we can just update it with the name1 and last_id $another_query = mysql_query("UPDATE table SET name2 ='$name1.$last_id' WHERE id='$last_id'"); hopefully that helps. There is a mysql function called last_insert_id() but I think that will be the same type of method i did here, but figured id mention it if you wanted to look into it. Quote Link to comment https://forums.phpfreaks.com/topic/184858-associating-field-and-id-in-database/#findComment-975872 Share on other sites More sharing options...
pioneerx01 Posted December 12, 2009 Author Share Posted December 12, 2009 It works beautifully. I had to tweak it to suit my needs, but it did the trick. Good man, thank you. You have saved me a lot of hours screaming at my monitor. Quote Link to comment https://forums.phpfreaks.com/topic/184858-associating-field-and-id-in-database/#findComment-976028 Share on other sites More sharing options...
pioneerx01 Posted December 16, 2009 Author Share Posted December 16, 2009 One more question with this. After the form is filled and submitted I have a PHP page that says something like: Thank you "john" (name entered in the form) for registering. I am having through. saying: your registration id is "John32" (what the previous question asked). How do I recall that from the database. I can not figure it out. Thanks a lot Quote Link to comment https://forums.phpfreaks.com/topic/184858-associating-field-and-id-in-database/#findComment-978219 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.