Jump to content

Recommended Posts

I searched throughout the internet and this forum for the answer, and either I didnt find it, or I didnt know what exactly I was looking for. But heres my problem:

 

I have a table of user information (username, passwords, emails, etc). It already has content and is fully functional for me.

I\'ve added an additional feature to my site, which has created its own user table (which is now empty), so my users have to re-register to use that feature.

My original table has more fields, and stores more information about the user. The new table has much less, basically just username, password and email.

Is there a way I can copy over the data from my original table to my new table, and make it so all new users get added to both tables? Is that a \"join\" command thing? What syntax do I use?

 

Thanks in advance

Link to comment
https://forums.phpfreaks.com/topic/857-table-join/
Share on other sites

here are my structures:

 

nkw_users (original user table):

 

uid int(11) NOT NULL auto_increment

uname varchar(25) NOT NULL

email varchar(60) NOT NULL

pass varchar(40) NOT NULL

(other fields)

 

cont_users (new user table):

 

id int(11) NOT NULL auto_increment

username varchar(50) NOT NULL

password varchar(40) NOT NULL

email varchar(255) NULL

Link to comment
https://forums.phpfreaks.com/topic/857-table-join/#findComment-2849
Share on other sites

will that keep it constantly updated?

 

No, its a one time transfer. If you are keeping both tables do it this way

 

1 Create new table without any auto_increment on uid but keep as primary key

 

2 Add \'uid\' field to my query and execute

INSERT INTO cont_users (uid, username, password,email) SELECT 

uid, uname, pass,email FROM nkw_users

 

3 drop uname, pass and email field from original table (don\'t want duplication.

 

4. Decide on which is to be the master table (prob the new one) and change to auto_inc on uid and take auto_inc off old table (or vice versa) so only one generates new uid. When adding new users, insert one with auto key first and write record with same key to other table.

 

5. Now for JOIN bit

To access data from both tables

SELECT * FROM cont_users c INNER JOIN nkw_users n ON c.uid = n.uid

 

hth

Link to comment
https://forums.phpfreaks.com/topic/857-table-join/#findComment-2856
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.