I'm running a calendar script, each day (td cell) is printed via a loop, for each day in the loop, I run a query to see if an "event" on my database "starts" or "finishes" that day.
Most of the time, the events start and finish on the same day, for that both the start and finish dates are the same (YYYYMMDD), but the odd event lasts a duration of days, & these days between have to be highlighted, and begins my headache.
Right now, in the loop, I run the date (YYYYYMMDD) through a bunch of different if statements to see if it meets any of that days unique features, ie; todays real date, an event on that date,
I found a way to "carry" an event a number of days (if the start and finish dates are different) but it doesn't work if event spans overlap as its using the same variable to "carry" the number of days and links to the next x days..
//..calendar stuff
while($day_num <= $days_in_month){ //month loop
//This day in the calendar in YYYYMMDD format
$today = $year.$month.$daynum;
//See if theres events today
$query = "SELECT start, finish FROM events WHERE finish = '{$today}' OR start = '{$today}'";
$result = mysql_query($query);
$row = mysql_fetch_array($result);
$finish = $row['finish']; //(YYYYMMDD)
$start = $row['start']; //(YYYYMMDD)
//normal days
$links = ""; //no links
$color = "#7b897a"; //main color
$underline = 0; //no underline
//If date is now; underline
if ($today == date('Ymd')) {
$underline = 1;
}
//If there is an event today, loop the links
if ($today == $finish) {
$result_query = mysql_query("SELECT * FROM events WHERE finish = '{$today}'");
while($result_row = mysql_fetch_array($result_query)) {
$links .= "<a href='?id={$result_row['id']}'>{$r_row['title']}</a><br />"; //add links
}
$color ='#91a490'; //highlight cell on calendar
}
//If the start is not equal to finish; lasts a duration of days
if ($start != $finish) {
//If there's an event start on date; print links on this date - up to finish date
if ($today == $start) {
$result_query = mysql_query("SELECT * FROM events WHERE start = '{$today}'") or die(mysql_error());
while($r_row = mysql_fetch_array($result_query)) {
//carry days including today
$carry = $r_row['finish'] - $r_row['start']; //I know I have to finish that, but for the sake of example it'll do
$carry_link = "<a href='?page=ticket&event={$r_row['id']}' title='{$r_row['title']}'>{$r_row['title']}</a><br />";
}
$color = '#91a490'; //highlight on calendar
}
}
//If a carry is present apend links
if ($carry != 0) {
$links .= $carry_link;
$carry = $carry-1;
$color = '#91a490';
}
//underline?
$u = ($underline == 1) ? "<span class='underline'>" : "" ;
$u1 = ($underline == 1) ? "</span>" : "" ;
//Print cell
echo "<td width='80' height='50' bgcolor='{$color}' class='cal' valign='top' align='left'>
<div style='padding:3px;'>{$u}{$day_num}{$u1}<br />{$links}</div>
</td>";
//....rest of calendar mombojumbo...
}
I'm hoping someone can point me in the right direction as to what's the best way to "carry" an event a number of days, but have that carry be unique so that two of them can accrue at once, overlapping each other ie; an event from the 1st - 6th will carry its unique properties (link and title), with and event from the 3rd - 10th with its own unquie properties (link and title),