Im developing an intranet website with an event calendar using MySQL, PHP and Javascript.
I have the calendar all set up and pulling test data from MySQL. So far everything looks good from that side.
I have a mysql database I called company and a table called eventcalendar. The table has columns for ID, Name, Description, Start_Date, End_Date and Current_Date. The date fields are just varchar fields because I want to be able to display the dates in the dd/mm/yyyy format rather than the yyyy/mm/dd format of a date field.
What I want is to come up with an insert statement that will post an individual row in mysql based on every date in the date range.
For example, if I have someone named Jim Smith who posts that he will be on vacation from april 25th through the 27th. The submission form and the mysql table should look like this.
Name: Jim Smith
Description: Vacation Day
Start_Date: 4/25/2016
End_Date: 4/27/2016
ID Name Description Start_Date End_Date Current_Date
1 Jim Smith Vacation Day 4/25/2016 4/27/201 4/25/2016
2 Jim Smith Vacation Day 4/25/2016 4/27/2016 4/26/2016
3 Jim Smith Vacation Day 4/25/2016 4/27/2016 4/27/2016
I know the start_date and end_date columns in the table aren't really necessary because I will be pulling that data to display in the calendar using the current_date field, but there shouldn't be any harm in having them there.
I've come up with a couple of separate loops. One puts multiple rows in sql based on the amount of days in the date range. The other loop increments the dates by adding a day each time the loop is run. They work great separately, but the problem is, I haven't been able to figure out how to get them to play nice together.
I was interested in seeing what others could come up with.
I have the calendar all set up and pulling test data from MySQL. So far everything looks good from that side.
I have a mysql database I called company and a table called eventcalendar. The table has columns for ID, Name, Description, Start_Date, End_Date and Current_Date. The date fields are just varchar fields because I want to be able to display the dates in the dd/mm/yyyy format rather than the yyyy/mm/dd format of a date field.
What I want is to come up with an insert statement that will post an individual row in mysql based on every date in the date range.
For example, if I have someone named Jim Smith who posts that he will be on vacation from april 25th through the 27th. The submission form and the mysql table should look like this.
Name: Jim Smith
Description: Vacation Day
Start_Date: 4/25/2016
End_Date: 4/27/2016
ID Name Description Start_Date End_Date Current_Date
1 Jim Smith Vacation Day 4/25/2016 4/27/201 4/25/2016
2 Jim Smith Vacation Day 4/25/2016 4/27/2016 4/26/2016
3 Jim Smith Vacation Day 4/25/2016 4/27/2016 4/27/2016
I know the start_date and end_date columns in the table aren't really necessary because I will be pulling that data to display in the calendar using the current_date field, but there shouldn't be any harm in having them there.
I've come up with a couple of separate loops. One puts multiple rows in sql based on the amount of days in the date range. The other loop increments the dates by adding a day each time the loop is run. They work great separately, but the problem is, I haven't been able to figure out how to get them to play nice together.
I was interested in seeing what others could come up with.
