Im new to php and have been struggling with this for some time, but I expect its something simple.

Basically I have some code below which I want to use to display an events board.
-Info for each event comes from a separate xml file for each event.
-XML files are named by date, ie today would be 050611.xml (DD/MM/YY)
-Load all XML files in a directory and display items by tag name automatically.

As it is my code works fine. It finds all files in the directory that = more than today date and adds them to an array.

Then an array element can be used to load the corresponding xml (see red) and show the result.

Now here is my problem, I need it to be able to repeat the process (see green) for each item in the array automatically even if the number of elements in the array changes.

...Perhaps some kind of wild card for $files[0] so that it repeats for all the array elements?

  //grab date
	$time = date("dmy");
  // create a handler to the directory
    $dirhandler = opendir($directory);
  // read all the files from directory
    while ($file = readdir($dirhandler)) {
      // if $file isn't this directory or its parent and is more than now 
      //add to the $files array
        if ($file != '.' && $file != '..' && $file >= $time-3600)
		  //arange by date			

  //grab file name from $files array and set xml location. then load.
  //$grab = ($files[0]);
	$source = ("pages/events/".($files[0]));
	$xmlDoc = new DOMDocument();

		//shows specific node data
			$x=$xmlDoc->getElementsByTagName( "_event_date" );
			$y=$xmlDoc->getElementsByTagName( "_event_title" );
			$z=$xmlDoc->getElementsByTagName( "_event_desc" );
	echo "<br/>";
	echo $x;
	echo "<br/>";
	echo "<br/>";
	echo $y;
	echo "<br/>";
	echo "<br/>";
	echo $z;
  //close the handler

Any help at all would be greatly appreciated, but please be patient I am learning! :)

6 Years
Discussion Span
Last Post by NuGG

Aha after all that, I've managed to figure something out!

If anyone wants to know, just add:

foreach($files as $key=>$value) { }

...and change...

$source = ("pages/events/".($files[0]));


$source = ("pages/events/".($value));

I love it when a plan comes together!

Edited by NuGG: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.