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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T04:06:54+00:00 2026-06-02T04:06:54+00:00

I’ve previously made a text file and turned it into multidimensional array to display

  • 0

I’ve previously made a text file and turned it into multidimensional array to display as the questions for my quiz.

Note: I am unable to insert images therefore I cannot provide any example so I’ll try to be as descriptive as I can.

I’m trying to display only one question at a time, every time a user clicks on my quiz.

This is my code so far. The main.php page:

<h2>ONLINE QUIZ</h2>
<ul>
    <li><a href='question.php'>Take quiz</a></li>
    <li><a href='module.php'>Admin Module</a></li>
</ul>
<?php

$file = fopen('data.txt', 'r');

$array = array();
while ($line = fgetcsv($file)) {
    $array[] = $line;
}

fclose($file);

session_start();
$_SESSION["questions_array"]=$array;

?>

And the question.php page:

<?php

session_start();
$array=$_SESSION["questions_array"];

foreach ($array as $q => $data) {
    echo '<p>'.array_shift($data).'</p>';
    foreach ($data as $a => $answer) {
        echo 
             '  <input type="radio" name="question-'.$q.'" id="question-'.$q.'"'.
             '         value="'.$a.'"/>'.
             '  <label for="question-'.$q.'">'.$answer.'</label>'.
             '<br>';
    }

}

?>

When the Take quiz link is clicked, the user is taken to the question page where only one question is shown. The user then picks an answer and hits submit. This submit button will take the user to the result page where they can then hit continue.

The Continue link will redirect them back to the question page where the next question is displayed.

From stuff that I’ve done before, I am attempting to use the isset() function to make this happen. However, the problem is that I’m not sure how exactly to write my isset().

I’ve found this snippet from this site, I’m not sure if it’s useful, but:

if (!isset($_SESSION['FirstVisit'])) {

    //show site for the first time part
    $_SESSION['FirstVisit] = 1;
    header("Location: http://example.com/index.php");

    // Don't forget to add http colon slash slash www dot before!

    } else { Show normal site }

But once again I found myself blank. How exactly do I use the isset() to display only one question?

  • 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-02T04:06:58+00:00Added an answer on June 2, 2026 at 4:06 am

    I kinda get what your asking, Ive jotted out the basic structure. This can all be done on one page, hope it helps.

    EDIT:

    As im such a nice guy heres a complete script, using my prev suggestion ;p

    <?php
    session_start();
    echo '<h2>ONLINE QUIZ</h2>';
    
    
    //Scores
    if($_SERVER['REQUEST_METHOD']=='GET' && isset($_GET['scores'])){
        echo 'Basic output for scores';
        echo '<pre>';
        print_r($_SESSION['answers']);
        echo '</pre>';
        unset($_SESSION['answers']);
        unset($_SESSION['question']);
    }
    
    
    //Session question/array is set
    if(isset($_SESSION['question']) && isset($_SESSION['questions_array'])){
    
        //Handle prev question post
        if($_SERVER['REQUEST_METHOD']=='POST'){
            //process prev question
            $_SESSION['answers'][$_SESSION['question']-1]=(0+$_POST['answer']);
        }
    
        if($_SESSION['question'] < $_SESSION['total_question']){
            $q=$_SESSION['question'];
            //EDIT - Shuffle answers for output
            //Hold the question into a var
            $question = $_SESSION['questions_array'][$q][0];
            //unset the question from the array
            unset($_SESSION['questions_array'][$q][0]);
            //put all the pos answers into a new array
            $answers = $_SESSION['questions_array'][$q];
            //shuffle the answers
            shuffle($answers);
    
    
            echo '<form method="POST" action="">
                  <h3>'.$question.'</h3>';
            //loop through the answers
            foreach($answers as $key=>$value){
                //if the value is nothing cont to next, removed question key 0
                if($value==''){continue;}else{
                    echo '<p><input type="radio" value="'.$value.'" name="answer">'.$value.'</p>';
                }
            }
            echo '<p><input type="submit" value="Submit"></p>
            </form>';
    
        }else{
            //Quiz Complete
            echo 'Test Complete <a href="'.basename($_SERVER["SCRIPT_FILENAME"]).'?scores=1">Check scores</a>';
        }
    
        //Assign next question to session
        $_SESSION['question']++;
    }else{
    
        //Pages first load so show quiz index
        $_SESSION['question']=0;
        get_questions();
    ?>
        <ul>
            <li><a href='<?=basename($_SERVER["SCRIPT_FILENAME"]);?>'>Take quiz</a></li>
            <li><a href='module.php'>Admin Module</a></li>
        </ul>
        <?php
    }
    
    //Function to put questions in session
    function get_questions(){
        $file = fopen('data.txt', 'r');
        $array = array();
        while ($line = fgetcsv($file,1000,',')) {
            $array[] = $line;
        }
        fclose($file);
        $_SESSION['questions_array']=$array;
        $_SESSION['total_question']=count($array);
        return;
    }
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
In my XML file chapters tag has more chapter tag.i need to display chapters
i want to parse a xhtml file and display in UITableView. what is the
I have a reasonable size flat file database of text documents mostly saved in
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into

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.