<?php
$LINK 
mysqli_connect('127.0.0.1','pisjo950','vjPRjFTxDVIoG7)t','pisjo950');
header('Content-type: text/calendar; charset=utf-8');
header('Content-Disposition: attachment; filename=calendar.ics');

echo 
"BEGIN:VCALENDAR\r\n";
echo 
"VERSION:2.0\r\n";
echo 
"PRODID:-//YourCompany//CineCalendar//EN\r\n";

// Fetch entries
$query "SELECT startDate, endDate, notes, fk_film_contains FROM CineEntry";
$result mysqli_query($LINK$query);

while(
$row mysqli_fetch_assoc($result)) {
    
$filmId $row['fk_film_contains'];
    
$filmQuery "SELECT title FROM CineFilm WHERE pk_film = $filmId";
    
$filmResult mysqli_query($LINK$filmQuery);
    
$film mysqli_fetch_assoc($filmResult);

    
$title $film['title'];
    
$description $row['notes'];
    
$start date('Ymd\THis'strtotime($row['startDate']));
    
$end date('Ymd\THis'strtotime($row['endDate']));

    echo 
"BEGIN:VEVENT\r\n";
    echo 
"SUMMARY:" addslashes($title) . "\r\n";
    echo 
"DESCRIPTION:" addslashes($description) . "\r\n";
    echo 
"DTSTART:$start\r\n";
    echo 
"DTEND:$end\r\n";
    echo 
"END:VEVENT\r\n";
}

echo 
"END:VCALENDAR\r\n";
?>