0

I'm using a plugin for calendar bookings and reservations. I can create more calendars, but I can't set different services, prices and payment methods in one calendar.

I need two different services for the same event, so I should create two calendars, but in this case there isn't a synchronization of booking days between the calendars: I need one calendar only.

So my intention is to synchronize both the calendars via PHP and MySQL. This plugin create a specific table called "days" in the calendar db for date, like this:

 | Calendar Id | Day                     | Month    | Year |
 |          01 |  01 monday available    |       01 | 2014 |
 |          01 |  02 tuesday available   |       01 | 2014 |
 |          01 |  03 wednesday booked    |       01 | 2014 |
 |          02 |  01 monday in pending   |       01 | 2014 |
 |          02 |  02 tuesday booked      |       01 | 2014 |
 |          02 |  03 wednesday available |       01 | 2014 |

How can I synchronize data (day, month, year) of calendar id 01 and calendar id 02?

I've found this: How can i synchronize two database tables with PHP?

But I need to syncronize data (records) and not tables or databases.

I hope that my questione is clair, sorry for my English and thanks in advance!

2
  • You should explain to use what you mean by "synchronize". Do you want to INSERT and/or UPDATE some rows? What is the logic you would like to implement? As is, this is not answerable. Commented Aug 1, 2014 at 22:46
  • Yes, sorry, I mean that if a client book a day in one of two calendars, both the calendars will be automatically updated with that day booked. Obviously it's very important to update (and rewrite data) in order of the last time (most recent booking). Commented Aug 2, 2014 at 7:39

1 Answer 1

1

You should create a new column to store if is available. | Calendar Id | Day | Month | Year | Available

Then, you can use a trigger:

    CREATE TRIGGER synchronize_update BEFORE UPDATE ON table
    FOR EACH ROW BEGIN
    UPDATE table SET Available = NEW.Available WHERE calendar_id <> NEW.calendar_id AND Day = New.Day And Month = NEW.Month  AND Year = NEW.Year;
    END;
Sign up to request clarification or add additional context in comments.

1 Comment

It doesn't work (maybe I wrong). Can I use DUPLICATE ON? In fact I need tou duplicate two data of different rows.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.