php - CSV and ID problems -
i have database employees in it.
since employer finds easy input info in csv file, wrote programme truncates database , inserts csv info in db.
employee: [id, last_name, name, email, remarks, ...] i utilize field id, (which auto_increment value) create employee's unique. works fine, employer has asked me include functionality mark favorites.
the thing makes employees unique id key when update new csv file id's go broke , shifted since had truncate database , favorites don't match more.
an illustration of mean (csv file):
0, carlton, john, john@gmail.com, "great worker", 1, awsome, dude, awsomedud@aol.com, "not great", 2, random, randy, rr@hotmail.com, "idk" suppose deletes record id 1. , favorite 1, csv file this:
0, carlton, john, john@gmail.com, "great worker", 1, random, randy, rr@hotmail.com, "idk" it points wrong person. maintain in mind id's wrote not part of csv file itself auto_increment value.
i have given problem lot of thought , cannot seem find simple way accomplish this.
any help appreciated.
notes:
emails not unique, nor required. the real unique field id field.
solution 1 (easiest)
have int is_favorite column in database containing 1 or 0, default value of 0 (meaning not favorite). inquire client alter format of csv file follows:
employee: [id, last_name, name, email, remarks, favorite, ...] example csv:
0, carlton, john, john@gmail.com, "great worker", 1 1, awsome, dude, awsomedud@aol.com, "not great", 0 2, random, randy, rr@hotmail.com, "idk" when process csv file, depending on favorite column set same value in database. eliminate problem mismatched favorites. unfortunately, if in near feature, client requires new features depend on favorites, might have same issue again.
solution 2 (best)
discuss more mature solution client pointing out current csv solution no longer valid alternative due issue matching csv users appropriate sub features (i.e. favorites)
php sql csv
No comments:
Post a Comment