Can someone assist me with my Events script?

Hi there,

Firstly, Just found this resource. It looks great :) Hello all.

I have a very basic events script that works with flat text files. It works like this.

I create a text file named as the date of the event. For example an event that is on 5th August 2004 will be named 20040805.txt. My upload script strips away the .txt.

Now the event will show until the date passes and then the event is hidden.

Now I need a variation of my display script so it only shows 1 event and that event has to be the event closest to todays event. I want to use it on the frontpage so I can display 'Our newxt event will be on ‘blah, blah, blah’.

I have this code and although it shows just the one date it shows the most recentely uploaded as against my need of the event closest to todays date.


<?php    
$date = date("Ymd", time()+3600*7);   
$NumEvents = 0;   
$handle = opendir('../event_dates'); 
$i=1;  

while (($file = readdir($handle)) !== false) {    
 if($i==1)  
 {  
   $hfile = $file;  
   $i++;  
  }  
 else  if ($hfile<=$file) {    
       $hfile = $file;    
   }  
}  

if($i!=1)  
 include '../event_dates/' . $hfile; 
else {   
   echo "<strong class='red'>Sorry, no events are planned at present</strong>";   
} 
?> 

Does anyone know how to tweak my script to allow what I need it to do?

Hope you can help.

Many thanks
Karl

I don’t work with directories much so take this with a grain of salt. Instead of linking only to the first file, loop through all the files and save their name maybe in an array. Then you can do some math subtracting the current date from the dates in the array. The results with the lowest difference should be the next event.

Sponsor our Newsletter | Privacy Policy | Terms of Service