I am trying to update a file that is blocked out like this
0,0,5,2,0
0,0,7,0,0
0,2,2,3,0
1,2,2,2,0
0,0,5,2,0
0,1,3,2,1
0,0,3,2,2
0,0,6,1,0
Each row is a question and each number in the row is the number of respondents. Here the code is attempting to go row by row and check which answer the user picked out of 5 radio buttons per question. So the format is something like:
Question 1: Blah | 1 | 2 | 3 | 4 | 5 | Check one
//Grab user input from survey
$q[1] = $_POST['radio1'];
$q[2] = $_POST['radio2'];
$q[3] = $_POST['radio3'];
$q[4] = $_POST['radio4'];
$q[5] = $_POST['radio5'];
$q[6] = $_POST['radio6'];
$q[7] = $_POST['radio7'];
$q[8] = $_POST['radio8'];
//Use file handle and write to file
$FileName = "results.csv";
$FileHandle = fopen($FileName, 'a+') or die("can't open file!!");
$i = 0;
while($row = fgetcsv($FileHandle)){
$j = 1;
for($i = 0; $i<8; $i++){
if($q[$j] == 1){
$row[0]++;
}
else if($q[$j] == 2){
$row[1]++;
}
else if($q[$j] == 3){
$row[2]++;
}
else if($q[$j] == 4){
$row[3]++;
}
else if($q[$j] == 5){
$row[4]++;
}
$j++;
}
}
Here is my solution to my problem, it may not be elegant but it works. The script has to pull in the values and update them at the end.