Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9012987
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T03:08:23+00:00 2026-06-16T03:08:23+00:00

I am trying to update a file that is blocked out like this 0,0,5,2,0

  • 0

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++;
    }
}   
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T03:08:25+00:00Added an answer on June 16, 2026 at 3:08 am

    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.

    <?php
    
    //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, 'r') or die("can't open file!!");
    
    $result = array();
    
    $i = 0;
    $j = 1;
    while(($row = fgetcsv($FileHandle, 1024, ",")) !== FALSE){
    
        if($q[$j] == 1){
            $temp[0] = $row[0] + 1;
            $temp[1] = $row[1];
            $temp[2] = $row[2];
            $temp[3] = $row[3];
            $temp[4] = $row[4]; 
        }
        else if($q[$j] == 2){
            $temp[0] = $row[0];
            $temp[1] = $row[1] + 1;
            $temp[2] = $row[2];
            $temp[3] = $row[3];
            $temp[4] = $row[4];
        }
        else if($q[$j] == 3){
            $temp[0] = $row[0];
            $temp[1] = $row[1];
            $temp[2] = $row[2] + 1;
            $temp[3] = $row[3];
            $temp[4] = $row[4];
        }
        else if($q[$j] == 4){
            $temp[0] = $row[0];
            $temp[1] = $row[1];
            $temp[2] = $row[2];
            $temp[3] = $row[3] + 1;
            $temp[4] = $row[4];
        }
        else if($q[$j] == 5){
            $temp[0] = $row[0];
            $temp[1] = $row[1];
            $temp[2] = $row[2];
            $temp[3] = $row[3];
            $temp[4] = $row[4] + 1;
        }
        $result[] = $temp;
        $j++;
    }
    fclose($FileHandle);
    
    $FileHandle = fopen($FileName, 'w') or die("can't open file!!");
    
    
    foreach($result as $line){
        fputcsv($FileHandle, $line);
    }
    
    fclose($FileHandle);
    
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to update (add/modify files) an existing JAR file, and this code (using
am trying to update my database table that looks like this name | file_name
I am trying to create a file with PHP here is my code: $file_to_send
I am trying to figure out when and how does Windows update File Access
How do I do this properly. I'm trying to name the sql file that
I have a flat file that is pipe delimited and looks something like this
Update So i have a textile with thousand of lines that looks like this
I am trying to commit a file that is out of date. I tried
I'm trying to make a very simple updater app that reads current version.txt file
Q: I'm trying to update a file in place, by using fopen mode r+

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.