views:

35

answers:

1

Hi,

I already have a table in phpmyadmin that contains users records. Each user has a unique admission number. I now want to add a new column to this table and was wondering how I can import data for this new column using just the admission number and new data.

Is this possible? I have a CSV but can't work out the best way to import the data without overwriting any existing records.

Thanks.

+1  A: 

As far as I can see, this is not possible. phpMyAdmin's import features are for whole rows only.

You could write a small PHP script that opens the CSV file using fgetcsv(), walks through every line and creates a UPDATE statement for each record:

UPDATE tablename SET new_column = "new_value" WHERE admission_number = "number"

you can then either output and copy+paste the commands, or execute them directly in the script.

Pekka
Ah thanks, I didn't think it looked like I phpmyadmin could do it. I'll use php.
Tom