Merging mySQL database with PHP while maintaining field -
background: group of students including me creating website merit system our school. had no experience in html, css, php or sql databases @ start. we've managed decently.
however, we've run problem updating database. every week, need merge table students csv, updated classes , department of education system. there thousands of students , each of them have details when updated can change others need stay same. example, have number of merits needs stay same when update details such year group or classes can change. thing is, update done of csv file may have new students need updated database , csv not in order. trying find solution allows 1 field same allow others change.
so we've tried load data infile unique key problem found while preserved merits, ignored other details , added new students.
edit: students have class field contains classes of student. when import, need able change still maintain merit field not in csv file. understand manually import suspect take long time run.
our code in php way.
tl;dr need find out how merge/import databases csv, changing specific fields of existing students , adding new students
thanks in advance , sorry long post. first post forgive me if make mistakes.
you need php script reads contents of file, line line preferably since csv. need use primary key unique identifier each csv line check whether record primary key value exists in database. if record primary key exists in database, use update query update merits only. if record cannot found primary key, use insert statement add new record database.
note: bolded bits steps required, in chronological order.
Comments
Post a Comment