Frage

I have a php script creating a calendar event for each 'event' that is stored in the post.

They are stored as ['listItem'][0], ['listItem'][1] etc for how ever many there are.

The code below is working in the sense that it creates a calendar event for each one. However, it is only taking the data from ['listItem'][0]. I need to work out a way to move on to the next variable in the $_POST each time.

So at the moment it puts 10 events if there are that many but they all go on the same day.

** The eventDate variable just stores a date.

Thanks in advance for any help.

foreach($_POST['listItem'] as $key => $value){

$eventDate = trim($_POST['listItem'][0]);

echo "BEGIN:VEVENT\n";
echo "METHOD:REQUEST\n"; // requied by Outlook
echo "DTSTART:".$eventDate."T190000Z\n";
echo "DTEND:".$eventDate."T193000Z\n";
echo "LOCATION:London\n";
echo "DESCRIPTION:Let's get together for New Years Eve\n";
echo "SUMMARY:".$eventDate."\n";
echo "DTSTAMP:".$eventDate."T190000Z\n";
echo "END:VEVENT\n";

}   
War es hilfreich?

Lösung

$eventDate = trim($_POST['listItem'][0]);

Should become

$eventDate = trim($value);

foreach will move on to the next element and update your $key and $value in every iteration.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top