I have a form used to update the following table where LoationName= $locationName
+--------+---------------------+--------------+------+
|Id |LocationName|TaskComplete | TaskNotes |
+--------+---------------------+--------------+------+
|001| NYC,FRA,UK |no,yes,no |NULL,Task Completed-FRA,NULL
|002| NYC,FRA,UK |no,no,yes |NULL,NULL,task-completed @ UK
|003| NYC,FRA,UK |no,no,yes |NULL,Task-started-FRA,completed Mar 3rd
How can I update the task-complete and task-notes col with the information corresponding to the correct locationName? If NYC updates their status the table should be updated as
+--------+---------------------+--------------+------+
|Id |LocationName|TaskComplete | TaskNotes |
+--------+---------------------+--------------+------+
|001| NYC,FRA,UK |yes,yes,no |NYC NOTES,Task Completed-FRA,NULL
|002| NYC,FRA,UK |yes,no,yes |NYC-Finished task2,NULL,task-completed @ UK
|003| NYC,FRA,UK |yes,no,yes |Completed-Tuesday,Task-started(FRA),completed Mar 3rd
I have a total of 100 task that must be completed by 25 locations. The following UPDATE statement will is ok but will not work in our scenario since it just updates the col with a single value i.e (“yes” or “no”).
UPDATE operations_checklist SET TaskComplete='$val' where TaskId IN($i)
I’m thinking my solution is to EXPLODE the TaskComplete values then use array_replace to update the necessary value-/position. What would be the best solution?
I may end up creating a table with 77 cols for TaskName, 77 cols for TaskNotes, 77 cols completeDate, etc… thoughts?
Since there isn’t a SPLIT function built in MySQL, using a query for this action isn’t mind acceptable, you will need write a FUNCTION yourself or write a long worthless algorithm to use built in functions for a such action …
I highly suggest to use php for this one as you said yourself and explode your data, replace what you want and then implode it back and update your record …
UPDATE
Just a note about your table structure, you could do this in place of your current structure:
Create a second table with this structure:
This table will be linked through FK to your main table and in place of using ~70 commas in a field there, use TaskType 1, 2, …, 70 in this and set the TaskStatus to true or false for yes and no, absenting a TaskType for a FK would also mean no here …