I’m building a availability calendar using the CodeIgniter’s calendar class.
I’m generating checkboxes for each day of the month:
[ ] Morning
[ ] Afternoon
[ ] Evening
Users can check or uncheck their availability for a certain day.
The POST array looks like this:
Array (
[2011-12-01] => Array (
[morning] => 1
[afternoon] => 1
)
[2011-12-02] => Array (
[evening] => 1
)
)
The data in the MySQL table would then look like this:
ID | date | data
- - - - - - - - - - - - - - -
1 | 2011-12-01 | 1-1-0
2 | 2011-12-02 | 0-0-1
The data value is morning-afternoon-evening 0 or 1.
If there’s no availability for a certain day (0-0-0) the row does not need to exist.
My solution would be to delete all of the rows of the month, and then insert all of the values (for example 1-0-0) for each day. That could be up to Insert 31 queries.
Question:
What’s the best solution for updating the table, without having run a lot of queries?
Thanks in advance!
PS.
I’m also not entirely sure about the way the data is stored. Perhaps a different row for each part of the day would be easier if I would like to update it upon change with jquery / ajax in the future. I would appriciate some thoughts on this as well.
The first thing I would do is separate the data field to make it more human readable. Something like this would work:
Secondly, I wouldn’t worry about running 31 INSERTs or UPDATEs against a database. I am not sure about your environment, but I have run scripts that update hundreds, thousands, and even tens of thousands of inserts/updates against a database. I have never noticed performance issues for anything as small as 31 queries.