Events calandar

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
kpraman
Forum Contributor
Posts: 172
Joined: Fri Oct 13, 2006 10:54 am

Events calandar

Post 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
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

I see no mention of year in the code... did you forget to add it?
kpraman
Forum Contributor
Posts: 172
Joined: Fri Oct 13, 2006 10:54 am

Post 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.
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post 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.
kpraman
Forum Contributor
Posts: 172
Joined: Fri Oct 13, 2006 10:54 am

Post 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
Last edited by kpraman on Tue Apr 10, 2007 5:59 am, edited 1 time in total.
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post by onion2k »

Well, you could start by spending more than 7 minutes thinking about it.
Post Reply