Quote (garrettthegreat @ Dec 20 2016 06:31pm)
Sorry, I was leaving it open ended so you'd be able to work through it yourself. You've got most of the hard work done! And, if this is a homework assignment, I'd be hurting you in the long run if I say too much.
Open the CSV like normal into your array. Edit the array with the changes from the form. You'll just add some code before your first output and after you've loaded the old CSV into the array to detect if a form is submitted (check your $_POST or $_GET). If so, make the edits to the array, then use implode with a comma delimiter, and write the new CSV one line at a time. Once that's done, print out your table like you have been doing.
I am taking a completely new approach, if you can maybe you can have a look:
Quote
<?php
echo '<table>';
$openFile = fopen("daten.csv", "r");
$i = 0;
// i = Zeile
while (($calendarWeek = fgetcsv($openFile, 1000, ";")) !== FALSE) {
if ($i == 0) {
for ($cW = 0; $cW < count($calendarWeek); $cW++) {
echo '<th>' . $calendarWeek[$cW] . '</th>' . "\n";
}
} else {
echo '<tr>' . "\n";
// cW = Spalte
for ($cW = 0; $cW < count($calendarWeek); $cW++) {
//echo '<td>' . redGreen() . '</td>' . "\n";
echo '<td>' . changeState($i, $cW, $calendarWeek[$cW]) . '</td>' . "\n";
}
echo '</tr>' . "\n";
}
$i++;
}
fclose($openFile);
echo '</table>';
?>
then on the same page:
Quote
function changeState($row, $col, $state)
{
"<a href=\"index.php?row=".$row."&col=".$col."&state=".$state."\">";
if ($col == 0) {
}
else{
}
}
the plan is to create a link for each entry, which reflects the row and column (user and week), and based on that knows whether to change the entry for both user and week specifically. SO if it was a 1 it will turn to 0 when clicked, if it was a 0 it will turn to a 1.
What do you think? a co-worker brought me this way.