Jump to content

Recommended Posts

Hi guys im using the following code
Code:





<?php
$questions = array('Op 5 Julie 2008 betaal Johan Steyn sy werknemers se weeklikse lone deur ‘n tjek vir R7 500 te wissel.*Watter twee algemene grootboek rekeninge sal gebruik word?','Ontvang ‘n tjek van C. Botha om sy rekening van R2 000 te vereffen; korting toegestaan is 5%.*Verduidelik wat gebeur met jou rekenkundige vergelyking. (Bankrekening is oortrokke)','Koop handelsware op krediet aan van Smit Traders vir R600 minus 10% korting.*Hoeveel gaan die handelsvoorraad nou kos?','Verkoop goedere op krediet aan E. Van der Merwe vir R500 (kosprys R200).*Watter van die volgende is waar?','‘n Tjek van R2 000 ontvang van Z. Kotzé vir goedere op skuld gekoop is deur die bank geweier.*Wat sal die invloed van die transaksie wees op die eienaarsbelang?','Watter een van die volgende transaksies sal pas by :<img src="http://rekvasvra.uni.me/img/table1vr6.jpg" width="239" height="79" longdesc="http://rekvasvra.uni.me/img/" />','Die eienaar S. Swart verhoog sy belang in die onderneming deur ‘n tjek van R50 000 te gee vir kapitaalbydrae.*Watter een van die volgende sal die regte inskrywing wees?','Skep ‘n voorsiening vir oninbare skulde teen 5%. (Debiteure is R40 000) Watter een is korrek? ','Watter een van die volgende transaksies sal pas by:<img src="http://rekvasvra.uni.me/img/table4vr9.jpg" width="239" height="79" longdesc="http://rekvasvra.uni.me/img/" />','Bereken die waardevermindering van die besigheidsvoertuig.*Drawaarde is R100 000 en die opgelope waardevermindering is R20 000.*(waardevermindering word op die verminderde saldo bereken teen 15%)*Wat is die waardevermindering?');
$answers = array(
// the correct answer for each question must be the first array item 0=>'item'
array(0 =>'Bank en Lone','Bank en Salarisse','Debiteure Kontrole en Lone','Kleinkas en Lone'),
array(0 => 'Bates – R2 000; Eienaarsbelang – R100;*Laste – R1 900','Bates – R2 000; Eienaarsbelang + R100;*Laste – R1 900','Bates – R2 000; Eienaarsbelang – R100;*Laste + R1 900','Bates + R2 000; Eienaarsbelang – R100;*Laste – R1 900'),
array(0 => 'R540','R60','R660','R600'),
array(0 => 'Debiteure + R500; Handelsvoorraad – R200','Debiteure + R500; Handelsvoorraad + R200','Krediteure + R500; Handelsvoorraad – R200','Krediteure + R500; Handelsvoorraad + R200'),
array(0 => 'A
<img src="http://rekvasvra.uni.me/img/otable2vr5a.jpg" width="239" height="79" name="A" longdesc="http://rekvasvra.uni.me/img/" />','B
<img src="http://rekvasvra.uni.me/img/otable2vr5b.jpg" width="239" height="79" name="B" longdesc="http://rekvasvra.uni.me/img/" />','C
<img src="http://rekvasvra.uni.me/img/otable2vr5c.jpg" width="239" height="79" name="C"
longdesc="http://rekvasvra.uni.me/img/" />','D <img src="http://rekvasvra.uni.me/img/otable2vr5d.jpg" width="239" height="79" name="D" longdesc="http://rekvasvra.uni.me/img/" />'),
array(0 => 'Huur ‘n gebou van Seeff eiendomme en betaal die huur per tjek, R1000','Betaal R10 000 kontant aan huuruitgawes','Ontvang R1000 vir perseel wat uit verhuur word','Die huuruitgawe het opgeloop en is agterstallig met ‘n R1000'),
array(0 => 'Kapitaal gekrediteer met R50 000; Bank gedebiteer met R50 000','Kapitaal gekrediteer met R50 000; Onttrekkings gedebiteer met R50 000','Bank gekrediteer met R50 000; Kapitaal gedebiteer met R50 000','Bank gedebiteer met R50 000; Kapitaal gedebiteer met R50 000'),
array(0 => 'A
<img src="http://rekvasvra.uni.me/img/otable3vr8a.jpg" width="239" height="79" name="A" longdesc="http://rekvasvra.uni.me/img/" />','B
<img src="http://rekvasvra.uni.me/img/otable3vr8b.jpg" width="239" height="79" name="B" longdesc="http://rekvasvra.uni.me/img/" />','C
<img src="http://rekvasvra.uni.me/img/otable3vr8c.jpg" width="239" height="79" name="C" longdesc="http://rekvasvra.uni.me/img/" />','D
<img src="http://rekvasvra.uni.me/img/otable3vr8d.jpg" width="239" height="79" name="D" longdesc="http://rekvasvra.uni.me/img/" />'),
array(0 => 'Wissel ‘n kontant tjek en betaal die lone van R800','Eienaar ontvang sy loon van R800','Wissel ‘n kontant tjek en betaal salarisse van R800','Eienaar verhoog sy kapitaal bydrae met R800'),
array(0 => 'R12 000','R11 000','R1 200','R15 000'),
);
?>

 


but im experiencing an error if I use the image links in the array if I load the page it appears as follow

post-141539-0-58766300-1362313315_thumb.jpg

can someone please help my edit this code to fix the problem not to show the tags above the image

Edited by cobusbo

as that code outputs nothing it's impossible to see what you doing wrong. I'm guessing it is somwhere in the radio tags

 

Also, could i| suggest a better array structure so you don't have to put the correct answer first every time eg http://forums.phpfreaks.com/topic/275096-writing-a-quiz-help/?do=findComment&comment=1415881

ok so wich document do you need to get to see what is wrong because normal text works but as soon as I place the img in there I get such an result dont know if this will help?

 

<?php
/**
 * Description of Quiz
 *
 * @author ben
 */
class Quiz {

    private $_answers;
    private $_questions;
    private $_leaders = array();
    private $_formattedAnswers = '';
    private $_leaderboard;
    private $_xml;
    private $_verdict = '';
    private $_output = '';
    private $_pattern = ' ';
    private $_replace = '_';

    public function __construct(array $answers, array $questions) {
        try {
            // need to have singleton db class that pulls specific quiz info from db based on quiz name params
            $this->_answers = $answers;
            $this->_questions = $questions;
            $this->_xml = simplexml_load_file(config::$leaderboardfile);
        } catch (Exception $e) {
            echo $e->getMessage();
        }
    }
    
    public function shuffle_assoc($array) {

        $keys = array_keys($array);
        shuffle($keys);
        $shuffled = array();
        foreach ($keys as $key) {
            $shuffled[$key] = $array[$key];
        }
        foreach ($shuffled as $answer) {
            $answer2 = str_replace($this->_pattern, $this->_replace, $answer);
            $this->_output .= "<li><input type=\"radio\" id=\"$answer2\" value=\"$answer2\" name=\"answers\" />\n";
            $this->_output .= "<label for=\"$answer2\">$answer</label></li>\n";
        }
        return $this->_output;
    }
    
    public function registerUser() {
        $username = trim(strip_tags(stripslashes($_POST['username'])));
        foreach ($this->_xml->user as $user) {
            if ($user->name == $username) {
                $_SESSION['error'] = 'U gebruikersnaam is alreeds gebruik.';
                header('Location: index.php');
                exit();
            }
        }
        $_SESSION['user'] = $username;
        $_SESSION['score'] = 0;
        $_SESSION['correct'] = array();
        $_SESSION['wrong'] = array();
        $_SESSION['finished'] = 'no';
        if (isset($_SESSION['error']))
            unset($_SESSION['error']);
        $_SESSION['num'] = 0;
        header('Location: test.php');
    }
    
    public function createRandomUser() {
        $random = rand(1,1000);
        $_SESSION['user'] = 'Anon' . $random;
        $_SESSION['score'] = 0;
        $_SESSION['correct'] = array();
        $_SESSION['wrong'] = array();
        $_SESSION['finished'] = 'no';
        $_SESSION['num'] = 0;
        header('Location: test.php');
    }
    
    public function giveVerdict() {
        $user = $this->_xml->addChild('user');
        $uname = $user->addChild('name', $_SESSION['user']);
        $uscore = $user->addChild('score', $_SESSION['score']);
        $this->_xml->asXML(Config::$leaderboardfile);

        $this->_verdict .= "<h2 id=\"score\">{$_SESSION['user']}, Jou finale uitslag is: </h2>\n
 <h3>{$_SESSION['score']}/10</h3><h4>Kommentaar:</h4>";
        if ($_SESSION['score'] <= 5) {
            $this->_verdict .= "<p id=\"verdict\"><span>S</span>everely <span>H</span>indered <span>I</span>n the <span>T</span>est!</p>\n";
        }
        if (($_SESSION['score'] <= 6)) {
            $this->_verdict .= "<p id=\"verdict\"><span>C</span>ould <span>R</span>ead <span>A</span>nd <span>P</span>ractice more.</p>\n";
        }
        if (($_SESSION['score'] >= 7) ) {
            $this->_verdict .= "<p id=\"verdict\"><span>A</span>ccountings a<span>R</span>e <span>S</span>o <span>E</span>asy!</p>\n";
        }
        if ($_SESSION['score'] >=  {
            $this->_verdict .= "<p id=\"verdict\"><span>S</span>uper <span>A</span>ccounting <span>S</span>pecialist</p>";
        }
        $this->_verdict .= "<p id=\"compare\"><a href=\"results.php\">Sien hoe vergelyk jy! <img src=\"images/arrow.png\" /></a></p>";
        
        return $this->_verdict;
    }

    public function showLeaders($limit, $group = null) {

        // Place all users and associated 
        // scores into the 'leaders' array.
        foreach ($this->_xml->user as $user) {
            $name = (string) $user->name;
            $score = (string) $user->score;
            $this->_leaders[$name] = $score;
        }

        // Sort the leaders array numerically, highest scorers first.	
        arsort($this->_leaders, SORT_NUMERIC);

        // Initialise our $counter variable to '1'.
        $counter = 1;

        // Start a html ordered list to hold the leaders.
        $this->_leaderboard = "<ul class=\"leaders\">\n";

        // Loop through the 'leaders' array and wrap each username and score
        // in <li> tags. If the user is the current $_SESSION['user'], wrap
        // the name/score in <strong> tags too.
        foreach ($this->_leaders as $key => $value) {
            // Check that $counter is less than $limit.
            if ($counter <= $limit) {
                if ( (isset($_SESSION['user'])) && ($key == $_SESSION['user']) ) {
                    $this->_leaderboard .= "<li><strong>$key:</strong> $value/". count($this->_questions) ."</li>\n";
                } else {
                    $this->_leaderboard .= "<li>$key: $value/". count($this->_questions) ."</li>\n";
                }
                // Check to see if $group parameter has been passed.
                // If it has, create separate lists according to the $group variable.
                if ($group) {
                    // Use the modulus operator(%) to create new sub-list if required.
                    if ( ($counter % $group == 0) && ($counter != $limit ) ) {
                        $this->_leaderboard .= "</ul>\n<ul class=\"leaders\">\n";
                    }
                }
            }
            // Increment the $counter.	
            $counter++;
        }
        // End the ordered list.
        $this->_leaderboard .= "</ul>\n";

        // return the ordered list.
        return $this->_leaderboard;
    }

    public function formatAnswers() {
        for ($x = 0; $x < count($this->_answers); $x++) {
            if ($x % 2 == 0) {
                $this->_formattedAnswers .= "<div class=\"qanda clear\">\n";
            } else {
                $this->_formattedAnswers .= "<div class=\"qanda\">";
            }
            $this->_formattedAnswers .= '<h4>Vraag ' . ($x + 1) . ': ' . $this->_questions[$x] . '</h4>';
            $this->_formattedAnswers .= "<ol>\n";
            for ($y = 0; $y < count($this->_answers[$x]); $y++) {
                if (($this->_answers[$x][$y] === $this->_answers[$x][0]) && (in_array($this->_answers[$x][$y], $_SESSION['correct']))) {
                    $this->_formattedAnswers .= "<li class=\"correctuser\">{$this->_answers[$x][$y]} (Korrek!)</li>\n";
                } else if ($this->_answers[$x][$y] === $this->_answers[$x][0]) {
                    $this->_formattedAnswers .= "<li class=\"correct\">{$this->_answers[$x][$y]}</li>\n";
                } else if (in_array($this->_answers[$x][$y], $_SESSION['wrong'])) {
                    $this->_formattedAnswers .= "<li class=\"wrong\">{$this->_answers[$x][$y]} (Eina!)</li>\n";
                } else {
                    $this->_formattedAnswers .= "<li>{$this->_answers[$x][$y]}</li>\n";
                }
            }
            $this->_formattedAnswers .= "</ol></div>\n";
            
        }
        return $this->_formattedAnswers;
    }

}
?>

<!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.0//EN" "http://www.wapforum.org/DTD/xhtml-mobile10.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="css/style.css" type="text/css" />
<title>Rekeningkunde Vasvra</title>
<script type="text/javascript" src="js/form.js"></script></head>
<body>
<div id="wrapper">
<div id="intro">
<h1>Neem die toets en sien hoe goed ken U Sekere aspekte binne Ontleding van Transaksies</h1>
<p>Elke vraag het 4 opsies kies een en kliek op Gaan Voort om na volgende vraag te beweeg.</p>
<p>Daar is 10 vrae om te voltooi en U uitslae sal teen die einde verskyn.</p>
<h4>Huidige Gebruiker: Anon865</h4> </div><!--intro-->
<div id="quiz">
<h2>Vraag 5:</h2>
<p><strong>‘n Tjek van R2 000 ontvang van Z. Kotzé vir goedere op skuld gekoop is deur die bank geweier. Wat sal die invloed van die transaksie wees op die eienaarsbelang?</strong></p>
<form id="questionBox" method="post" action="processor.php">
<ul>
<li><input type="radio" id="D_<img_src="http://rekvasvra.uni.me/img/otable2vr5d.jpg"_width="239"_height="79"_name="D"_longdesc="http://rekvasvra.uni.me/img/"_/>" value="D_<img_src="http://rekvasvra.uni.me/img/otable2vr5d.jpg"_width="239"_height="79"_name="D"_longdesc="http://rekvasvra.uni.me/img/"_/>" name="answers" />
<label for="D_<img_src="http://rekvasvra.uni.me/img/otable2vr5d.jpg"_width="239"_height="79"_name="D"_longdesc="http://rekvasvra.uni.me/img/"_/>">D <img src="http://rekvasvra.uni.me/img/otable2vr5d.jpg" width="239" height="79" name="D" longdesc="http://rekvasvra.uni.me/img/" /></label></li>
<li><input type="radio" id="A
<img_src="http://rekvasvra.uni.me/img/otable2vr5a.jpg"_width="239"_height="79"_name="A"__longdesc="http://rekvasvra.uni.me/img/"_/>" value="A
<img_src="http://rekvasvra.uni.me/img/otable2vr5a.jpg"_width="239"_height="79"_name="A"__longdesc="http://rekvasvra.uni.me/img/"_/>" name="answers" />
<label for="A
<img_src="http://rekvasvra.uni.me/img/otable2vr5a.jpg"_width="239"_height="79"_name="A"__longdesc="http://rekvasvra.uni.me/img/"_/>">A
<img src="http://rekvasvra.uni.me/img/otable2vr5a.jpg" width="239" height="79" name="A" longdesc="http://rekvasvra.uni.me/img/" /></label></li>
<li><input type="radio" id="B
<img_src="http://rekvasvra.uni.me/img/otable2vr5b.jpg"_width="239"_height="79"_name="B"_longdesc="http://rekvasvra.uni.me/img/"_/>" value="B
<img_src="http://rekvasvra.uni.me/img/otable2vr5b.jpg"_width="239"_height="79"_name="B"_longdesc="http://rekvasvra.uni.me/img/"_/>" name="answers" />
<label for="B
<img_src="http://rekvasvra.uni.me/img/otable2vr5b.jpg"_width="239"_height="79"_name="B"_longdesc="http://rekvasvra.uni.me/img/"_/>">B
<img src="http://rekvasvra.uni.me/img/otable2vr5b.jpg" width="239" height="79" name="B" longdesc="http://rekvasvra.uni.me/img/" /></label></li>
<li><input type="radio" id="C_
<img_src="http://rekvasvra.uni.me/img/otable2vr5c.jpg"_width="239"_height="79"_name="C"
longdesc="http://rekvasvra.uni.me/img/"_/>" value="C_
<img_src="http://rekvasvra.uni.me/img/otable2vr5c.jpg"_width="239"_height="79"_name="C"
longdesc="http://rekvasvra.uni.me/img/"_/>" name="answers" />
<label for="C_
<img_src="http://rekvasvra.uni.me/img/otable2vr5c.jpg"_width="239"_height="79"_name="C"
longdesc="http://rekvasvra.uni.me/img/"_/>">C
<img src="http://rekvasvra.uni.me/img/otable2vr5c.jpg" width="239" height="79" name="C"
longdesc="http://rekvasvra.uni.me/img/" /></label></li>
</ul>
<p><input type="hidden" name="num" value="4" />
<input type="hidden" name="submitter" value="TRUE" />
<input type="submit" id="submit" name="submit" value="Gaan Voort" /></p>
</form>
</div><!--quiz-->
</div><!--wrapper-->
</body>
</html>
 

Definitely your other script is the problem. You are including the image as a "name" for the checkbox. You'll need to post or fix the other script.

Well the A B or D I just tried to put in text to see if it didnt fix the problem with the 



" value="D_" name="answers" /> ">D

showing up if I put in normal text there is no problem but as soon as I put the img_src code the above appears. what should I fix because im lost dont know where to start. I want to place the images as options to select from

 

<?php //processor.php
/*********Copyright (c) 2009 Ben Hall*********

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
 */
include 'functions.php';
session_name("Simple-Quiz");
$session = Session::get_instance();
require('res/questionsandanswers.php');
$quiz = new Quiz($answers, $questions);
if (!isset($_POST['submitter'])) {

    if (isset($_POST['register'])) {
        $quiz->registerUser();
    } else {
        $quiz->createRandomUser();
    }
} else {
    
    $_SESSION['num'] = (int) $_POST['num'];
    $num = $_SESSION['num'];
    $postedanswers = str_replace("_", " ", $_POST['answers']);
    if ($postedanswers == $answers[$num]['0']) {
        $_SESSION['score']++;
        $_SESSION['correct'][] = $postedanswers;
    } else {
        $_SESSION['wrong'][] = $postedanswers;
    }
    if ($_SESSION['num'] < count($questions) - 1) {
        $_SESSION['num']++;
    } else {
        $_SESSION['last'] = true;
        $_SESSION['finished'] = 'yes';
    }
    header('Location: test.php');
}
?>
Edited by cobusbo

Place the img tag after the radio input tag, not inside it.

but if I do so then it won't pop up as the radio option? see post #1 I placed it in the array so it can auto select wich one is correct if I move it out of there it will not pop up for that question only? Or should I make the 4 pictures 1 picture with options A B C and D and place it in the Question and Just place The options ABCD as the options for the radio input tag?

The thing is Im using a script I downloaded from Sourceforge and Im just trying to edit it to fit my needs and trying to change the structure wont fit in its layout im using the script im using can be found here so im trying to fit my needs for my Website

 

I agree changing the structure will be a good Idea but I don't have the knowledge to trans code it so it fit with the other part of the coding structure. So im just trying to do the best of a bad situation and modify the basics for now so the problem can be resolved. The thing is these radio boxes works it would had been just been more neat if it didn't pop up the unnecessary coding

 

Thank you for all the support so far Barnard I appreciate your patience.

Is this the part of code you guys need to help me fix this situation?

 

<?php
//test.php
/* * *******Copyright (c) 2009 Ben Hall*********

  Permission is hereby granted, free of charge, to any person
  obtaining a copy of this software and associated documentation
  files (the "Software"), to deal in the Software without
  restriction, including without limitation the rights to use,
  copy, modify, merge, publish, distribute, sublicense, and/or sell
  copies of the Software, and to permit persons to whom the
  Software is furnished to do so, subject to the following
  conditions:

  The above copyright notice and this permission notice shall be
  included in all copies or substantial portions of the Software.

  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
  OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  OTHER DEALINGS IN THE SOFTWARE.
 */
include 'functions.php';
session_name("Simple-Quiz");
$session = Session::get_instance();
$num = isset($_SESSION['num']) ? $_SESSION['num'] : 0;
require('res/questionsandanswers.php');
$quiz = new Quiz($answers, $questions);
?>
<!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.0//EN" "http://www.wapforum.org/DTD/xhtml-mobile10.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <link rel="stylesheet" href="css/style.css" type="text/css" />
    <title>Rekeningkunde Vasvra</title>
    <?php
    if (!isset($_SESSION['last'])) {
        echo "<script type=\"text/javascript\" src=\"js/form.js\"></script>";
    }
    ?>
</head>
<body>
    <div id="wrapper">
        <div id="intro">
            <h1>Neem die toets en sien hoe goed ken U Sekere aspekte binne in Rente Berekening</h1>
            <p>Elke vraag het 4 opsies kies een en kliek op Gaan Voort om na volgende vraag te beweeg.</p>
            <p>Daar is 10 vrae om te voltooi en U uitslae sal teen die einde verskyn.</p>
            <?php if (isset($_SESSION['user'])) echo "<h4>Huidige Gebruiker: {$_SESSION['user']}</h4>"; ?>
        </div><!--intro-->
        <div id="quiz">
        <?php if (!isset($_SESSION['last'])) { ?>
                <h2>Vraag <?php echo $num + 1; ?>:</h2>
                <p><strong><?php echo $questions[$num]; ?></strong></p>
                <form id="questionBox" method="post" action="processor.php">
                    <ul>
                        <?php
                        echo $quiz->shuffle_assoc($answers[$num]);
                        ?>
                    </ul>
                    <p><input type="hidden" name="num" value="<?php echo $num; ?>" />
                        <input type="hidden" name="submitter" value="TRUE" />
                        <input type="submit" id="submit" name="submit" value="Gaan Voort" /></p>
                </form>
            <?php
            } else {
                echo $quiz->giveVerdict();
            }
            ?>
        </div><!--quiz-->
    </div><!--wrapper-->
</body>
</html>

I have cleaned up the shuffle_assoc() method for you. Comment out the old one (for safety) and add this one

 

    public function shuffle_assoc($array) {

        $keys = array_keys($array);
        shuffle($keys);
        $shuffled = array();
        foreach ($keys as $key) {
            $shuffled[$key] = $array[$key];
        }
        foreach ($shuffled as $answer) {
            #$answer2 = str_replace($this->_pattern, $this->_replace, $answer);
            $option = $answer[0];
            $id = "answer$option";
            $this->_output .= "<li><input type=\"radio\" id=\"$id\" value=\"$option\" name=\"answers\" />\n";
            $this->_output .= "<label for=\"$id\">$answer</label></li>\n";
        }
        return $this->_output;
    }

like this?

<?php
//test.php
/* * *******Copyright (c) 2009 Ben Hall*********

  Permission is hereby granted, free of charge, to any person
  obtaining a copy of this software and associated documentation
  files (the "Software"), to deal in the Software without
  restriction, including without limitation the rights to use,
  copy, modify, merge, publish, distribute, sublicense, and/or sell
  copies of the Software, and to permit persons to whom the
  Software is furnished to do so, subject to the following
  conditions:

  The above copyright notice and this permission notice shall be
  included in all copies or substantial portions of the Software.

  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
  OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  OTHER DEALINGS IN THE SOFTWARE.
 */
include 'functions.php';
session_name("Simple-Quiz");
$session = Session::get_instance();
$num = isset($_SESSION['num']) ? $_SESSION['num'] : 0;
require('res/questionsandanswers.php');
$quiz = new Quiz($answers, $questions);
?>
<!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.0//EN" "http://www.wapforum.org/DTD/xhtml-mobile10.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <link rel="stylesheet" href="css/style.css" type="text/css" />
    <title>Rekeningkunde Vasvra</title>
    <?php
    if (!isset($_SESSION['last'])) {
        echo "<script type=\"text/javascript\" src=\"js/form.js\"></script>";
    }
    ?>
</head>
<body>
    <div id="wrapper">
        <div id="intro">
            <h1>Neem die toets en sien hoe goed ken U Sekere aspekte binne in Rente Berekening</h1>
            <p>Elke vraag het 4 opsies kies een en kliek op Gaan Voort om na volgende vraag te beweeg.</p>
            <p>Daar is 10 vrae om te voltooi en U uitslae sal teen die einde verskyn.</p>
            <?php if (isset($_SESSION['user'])) echo "<h4>Huidige Gebruiker: {$_SESSION['user']}</h4>"; ?>
        </div><!--intro-->
        <div id="quiz">
        <?php if (!isset($_SESSION['last'])) { ?>
                <h2>Vraag <?php echo $num + 1; ?>:</h2>
                <p><strong><?php echo $questions[$num]; ?></strong></p>
                <form id="questionBox" method="post" action="processor.php">
<ul>
  <?php
     public function shuffle_assoc($array) {

        $keys = array_keys($array);
        shuffle($keys);
        $shuffled = array();
        foreach ($keys as $key) {
            $shuffled[$key] = $array[$key];
        }
        foreach ($shuffled as $answer) {
            #$answer2 = str_replace($this->_pattern, $this->_replace, $answer);
            $option = $answer[0];
            $id = "answer$option";
            $this->_output .= "<li><input type=\"radio\" id=\"$id\" value=\"$option\" name=\"answers\" />\n";
            $this->_output .= "<label for=\"$id\">$answer</label></li>\n";
        }
        return $this->_output;
    }                   
                        ?>
</ul>
<p><input type="hidden" name="num" value="<?php echo $num; ?>" />
                        <input type="hidden" name="submitter" value="TRUE" />
                        <input type="submit" id="submit" name="submit" value="Gaan Voort" /></p>
                </form>
            <?php
            } else {
                echo $quiz->giveVerdict();
            }
            ?>
        </div><!--quiz-->
    </div><!--wrapper-->
</body>
</html>

 

because now they say theres an error in line 60?

ok I replaced it and the additional tags are gone but now it doesnt do the calculations correctly it shows the first answer as green and results is 0 out of 10 so the coding is incorrect somewhere

Put A,B,C or D as the first character of each answer option as you have with the image answers EG

array(0 => 'C) R12 000',' B) R11 000','D) R1 200','A) R15 000')


Mix up the sequences or the correct answer (first one) will always have same letter

Then, in processor.php, change the line

if ($postedanswers == $answers[$num]['0']) {


to

if ($postedanswers == $answers[$num][0][0]) {

 
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.