Here is a solution which will surely help you...
This is the example which i tried..
If you add a unique index on (userid, days):
-- run this only once ALTER TABLE availability ADD UNIQUE INDEX userid_days_UQ -- just a name for the index (userid, days) ;
then you can use the ON DUPLICATE KEY UPDATE syntax:
$q = " INSERT INTO availability (userid, days, opentime, closetime) VALUES (?, 'Monday', ?, ?), (?, 'Tuesday', ?, ?), (?, 'Wednesday', ?, ?), (?, 'Thursday', ?, ?), (?, 'Friday', ?, ?), (?, 'Saturday', ?, ?), (?, 'Sunday', ?, ?) ON DUPLICATE KEY UPDATE opentime = VALUES(opentime), closetime = VALUES(closetime) ; ";