Page 1 of 1

Events calandar

Posted: Tue Apr 10, 2007 1:19 am
by kpraman
Hello,


I have an event calendar. It shows the events of month, date etc. but it shows the events for all year (previous and also past). For example, if i add an event from apr 1 to apr 10 2007 . It shows that event for any year we select. I think, its not taking year to consideration. Pls help me out.

Here is the code

Code: Select all

function getDisplay(&$row,$months,$day,$year)
{
// Show Link or not
$month = abs($months);
$show = 'NO';
//echo $month;
echo $year;
if($row['MONTH1']==$month)
{
   if($row['MONTH']<$month)
   {	
						
      if($row['DAY1']>=$day)
     $show='YES';
   }
else if($row['MONTH']==$month)
{
   if($row['DAY1']>=$day && $row['DAY']<=$day)
   $show = 'YES';
}
if($row['DAY1']>=$day && $row['DAY']<=$day)
$show = 'YES';
}
else if($row['MONTH1']>$month){
if($row['DAY']<=$day)
$show = 'YES';
}
else if($row['MONTH1']<$month)
$show = 'NO';
return $show;
}
DB table field names
ID DAY MONTH YEAR DAY1 MONTH1 YEAR1 TITLE

DAY- starting date
DAY1-ending date
similarly for month and year

Thanks

Posted: Tue Apr 10, 2007 2:41 am
by Kieran Huggins
I see no mention of year in the code... did you forget to add it?

Posted: Tue Apr 10, 2007 4:55 am
by kpraman
this is the code i have. I tried,

1.

Code: Select all

if($row['YEAR']==$year)
{
// Show Link or not 
$month = abs($months); 
...........................
.........................
}
return $show;
This works, but if we give a date which has 2 years (example: starting date 31/12/2007 ending date 1/1/2008) it won't work.

Posted: Tue Apr 10, 2007 5:47 am
by onion2k
Rather than selecting all the events in the database and then checking each one to see if you should display it, you ought to just select the events that will be displayed. Your current system is hopelessly unscalable. If you have 10,000 events in the database it'll be incredibly slow.

Also, the line "$month = abs($months);" would concern me. Why on Earth would you be sending a negative value for the month?

And, "DAY- starting date, DAY1-ending date" .. why aren't they called something like start_date and end_date? Cryptic column names will be a problem for whoever has to maintain the code.

Posted: Tue Apr 10, 2007 5:54 am
by kpraman
Its allready implemented, i have to do modification. So it would be easy if the existing code is modified to show the years correctly

Posted: Tue Apr 10, 2007 5:56 am
by onion2k
Well, you could start by spending more than 7 minutes thinking about it.