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 8998549
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:03:01+00:00 2026-06-16T00:03:01+00:00

Hey this is my first post so I hope I am approaching this properly

  • 0

Hey this is my first post so I hope I am approaching this properly but anyway, I have a survey in which a user is presented with 8 questions and they are supposed to rate how they feel about each question by clicking the radio buttons valued from 1(strongly disagree)-5(strongly agree). So what I need to do is record the frequency in which each radio button is selected. Something like this:

$filename = "Results.txt";
$lines = file($filename); 
$q1 = $_POST['q1'];
$q2 = $_POST['q2'];
$q3 = $_POST['q3'];
$q4 = $_POST['q4'];
$q5 = $_POST['q5'];
$q6 = $_POST['q6'];
$q7 = $_POST['q7'];
$q8 = $_POST['q8'];

foreach($lines as $line) {  
        echo $line;
        if (isset($q1)){
            echo $line[$q1];
            echo $lines;
        }
    }

Where q represents question#.
Lastly this needs to keep a running calc and the results.txt should look something like this:
0,0,5,0,0
0,0,0,0,0
0,0,0,0,0
0,0,0,0,0
0,0,0,0,0
0,0,0,0,0
0,0,0,0,0
0,0,0,0,0
The 5 in line one means 5 users submitted a neutral radio button option (value 3). Each line represents the tally for each question.

Please help!

  • 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-16T00:03:02+00:00Added an answer on June 16, 2026 at 12:03 am

    Something like this should answer your “question” at hand, but also yes you should move this application to use a database.

    $filename = "Results.txt";
    $lines = file($filename);
    
    $q1 = $_POST['q1']; //stored value between 1-5
    $q2 = $_POST['q2'];
    $q3 = $_POST['q3'];
    $q4 = $_POST['q4'];
    $q5 = $_POST['q5'];
    $q6 = $_POST['q6'];
    $q7 = $_POST['q7'];
    $q8 = $_POST['q8'];
    
    $qN = 1;  //question number
    $newLines = '';
    foreach($lines as $line) {
    
        echo $line;
    
        $line = trim($line);  //remove excess newlines etc.
        $lineArr = explode(',',$line);  //split line into array by commas
        $index = ${'q'.$qN}-1; //zero based
        if (isset($lineArr[$index])){
            $lineArr[$index]++;  //add to position by one vote.
        }
        $qN++;
        $newLines .= implode(',',$lineArr) . "\n";
    }
    
    //write contents back to file.
    file_put_contents($filename, $newLines);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey this might be a simple question, but i have been stumped on it
hey guys having this really simple problem but cant seem to figure out have
Hey,firends,This is my first post. I'm just begin to using Gcc to compile java,and
Hey guys, this is my first time actually posting at stackflow but i've used
Hey! This is what I have already done so far which works great: Download
Hey stackoverflow - This is my first question here. I have 2 tables in
Hey all, first post and a noob in Android programming, but willing to learn!
Hey. You may have recently seen a post by me looking for help, but
Hey this is my first post so tell me if I am not giving
Hey, this is my first post on stackoverflow. I'm trying to replace é with

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.