# Solved: php and mysql. complex copy table data to another table



## firestormer (Sep 16, 2005)

i need to create some php code that when called updates another table with different field names in the following way. Some are staight forward copies but others involve if statements.

old->new

user_id -> user_id
group_id -> group_id but if = 11 then set as 1 and if = 15 set as 2
username -> username
username -> display_name
user_password ->password
user_email -> email

also in the new 

active needs to be set to 0 for all new records unless there is already a record with it set as 1

not that simple is it?

Thanks


----------



## Mudley (Apr 7, 2008)

pretty simple.

how many records are in the old table?


----------



## firestormer (Sep 16, 2005)

Unknown as it's going to be run to syncronise two systems on a regular basis


----------



## Mudley (Apr 7, 2008)

your going to maintain two seperate databases with the same data? *veggie face*

ok. still simple, but you have to explain the active column.

all new records have active = 0
unless there is already a record with it set at 1 <-- what does this mean?


----------



## firestormer (Sep 16, 2005)

It's ok. Basicly i've been trying to set up a cms and a board to share the same user data, names pw ect. originaly i tried to modify one table with extra fields to accomadate the cms and atempt to change the table name, but that failed. 

What i was planning to do was every time a user tried loging in to the cms was to copy all the data from the board user table into the cms user table.

Instead i've now managed to set it so that when a user trys logging into the cms it runs a select query on the board user table searching for the username and copies that record into an array which is then proccessed into the right field names then the cms user table is checked for that user if the num of rows found is 1 then it runs and update query if 0 it inserts the data.

You might be worried about data concurency and stuff but i've disabled the cms's user preferences and stuff so that the user can't change their password/details in the cms.

SOLVED!


----------



## firestormer (Sep 16, 2005)

Thanks for your time


----------

