Jump to content

Recommended Posts

Hey guys im a bit stuck here, i was wondering how youd put the answer,ranswer,ranswer1,ranswer2 into an array, and use the rand function to switch the postions of the answer....so that there not in the same position.

 

 

<?php



include('database_access_param.php');
include('auth.php');

$qid=$_POST['qid'];
$quesid=$_POST['quesid'];
$totalCorrect=$_POST['totalCorrect'];
$score=$_POST['score'];
$taken=$_POST['taken'];
import_request_variables("pgc","");


if(isset($_GET['quesid']))
{

   $quesid=$_GET['quesid'];
}


if(isset($_GET['qid']))
{

   $qid=$_GET['qid'];

}
if(isset($_GET['totalCorrect']))
{

   $totalCorrect=$_GET['totalCorrect'];

}
if(isset($_GET['score']))
{

   $score=$_GET['score'];

}
if(isset($_GET['taken']))
{

   $taken=$_GET['taken'];

}

    mysql_connect( $hostname, $dbuser, $dbpassword)
        or die ( 'Unable to connect to server' );

    

    mysql_select_db($dbname )
        or die ( 'Unable to select database' );


    $sql = "SELECT * FROM questiona WHERE qid = '$qid' && quesid = '$quesid' ";




                print("</head>");
                print('<BODY onLoad="goNewWin()">');
                print('<form action="grad.php?qid=$qid&quesid=$quesid&totalCorrect=$totalCorrect&taken=$taken" method="post" id="quiz">');
                print('<table class="report" align=left width=100%>');
                
                print('<tr><td> </td></tr>');


                $result=mysql_query($sql) or die ('Unable execute the query');
;



                if(mysql_numrows($result))
                {
                                $row = mysql_fetch_row($result);
                                {

                                $questid=$row[0];
                                $quesid=$row[1];
                                $question=$row[2];
                                $ranswer=$row[3];
                                $ranswer1=$row[4];
                                $ranswer2=$row[5];
                                $answer=$row[6];
                                $qid=$row[7];


print('<body>');

                                

        print('<tr><td >'.$quesid.'   '.$question.'</td>'.$Quiz_Topic.'</tr>');

        print('<input type= hidden name=qid value="'.$qid.'">');

        print('<input type= hidden name=totalCorrect value="'.$totalCorrect.'">');

        print('<input type= hidden name=quesid value="'.$quesid.'">');

        print('<input type= hidden name=score value="'.$score.'">');

        print('<input type= hidden name=taken value="'.$taken.'">');
      
        print('<tr><td><input type="radio" name="answer" id="answer" value="'.$ranswer .'">   '.$ranswer.'</td></tr>');

        print('<tr><td><input type="radio" name="answer" id="answer" value="'.$ranswer1 .'">   '.$ranswer1 .'</td></tr>');

        print('<tr><td><input type="radio" name="answer" id="answer" value="'.$ranswer2 .'">   '.$ranswer2 .'</td></tr>');

        print('<tr><td><input type="radio" name="answer" id="answer" value="answer">   '.$answer .'</td></tr>');

        print('<tr><td> <input type=hidden name=rightanswer value="'.$answer.'"><input type= hidden name=qnumber value="'.$question.'"></tr>');


        }
        print('<tr><td colspan=2><input type=submit name=submit value="Submit" ><input type=reset name=reset value="Clear" ></td></tr></table>');
        
         
        print('</form>');

        }
else
        {

         echo "<div id='results'>Your result is:  $score%</div>";
        print('<input type =hidden name=score value="'.$score.'">');
        print('</form>');

        }


?>

Hey I did as u said, Which shuffles all the values around but the answer stays in the same position

<?php



include('database_access_param.php');
include('auth.php');


$right=0;

$qid=$_POST['qid'];
$quesid=$_POST['quesid'];
$totalCorrect=$_POST['totalCorrect'];
$score=$_POST['score'];
$taken=$_POST['taken'];
import_request_variables("pgc","");


if(isset($_GET['quesid']))
{

   $quesid=$_GET['quesid'];
}


if(isset($_GET['qid']))
{

   $qid=$_GET['qid'];

}
if(isset($_GET['totalCorrect']))
{

   $totalCorrect=$_GET['totalCorrect'];

}
if(isset($_GET['score']))
{

   $score=$_GET['score'];

}
if(isset($_GET['taken']))
{

   $taken=$_GET['taken'];

}

    mysql_connect( $hostname, $dbuser, $dbpassword)
        or die ( 'Unable to connect to server' );

    

    mysql_select_db($dbname )
        or die ( 'Unable to select database' );


    $sql = "SELECT * FROM questiona WHERE qid = '$qid' && quesid = '$quesid' ";




	print("</head>");
	print('<BODY onLoad="goNewWin()">');
	print('<form action="grad.php?qid=$qid&quesid=$quesid&totalCorrect=$totalCorrect&taken=$taken" method="post" id="quiz">');
	print('<table class="report" align=left width=100%>');

	print('<tr><td> </td></tr>');


	$result=mysql_query($sql) or die ('Unable execute the query');
;



	if(mysql_numrows($result))
	{
			$row = mysql_fetch_row($result);
			{

			$questid=$row[0];
			$quesid=$row[1];
			$question=$row[2];
			$ranswer=$row[3];
			$ranswer1=$row[4];
			$ranswer2=$row[5];
			$answer=$row[6];
			$qid=$row[7];

$answer = array($ranswer,$ranswer1,$ranswer2,$answer);
shuffle ( $answer );





print('<body>');



print('<tr><td >'.$quesid.'   '.$question.'</td>'.$Quiz_Topic.'</tr>');

print('<input type= hidden name=qid value="'.$qid.'">');

print('<input type= hidden name=totalCorrect value="'.$totalCorrect.'">');

print('<input type= hidden name=quesid value="'.$quesid.'">');

print('<input type= hidden name=score value="'.$score.'">');

print('<input type= hidden name=taken value="'.$taken.'">');
      
print('<tr><td><input type="radio" name="answer" id="answer" value="'.$ranswer0.'">   '.$ranswer.'</td></tr>');

print('<tr><td><input type="radio" name="answer" id="answer" value="'.$ranswer1 .'">   '.$ranswer1 .'</td></tr>');

print('<tr><td><input type="radio" name="answer" id="answer" value="'.$ranswer2 .'">   '.$ranswer2 .'</td></tr>');

print('<tr><td><input type="radio" name="answer" id="answer" value="answer">   '.$answer .'</td></tr>');

print('<tr><td> <input type=hidden name=rightanswer value="'.$answer.'"><input type= hidden name=qnumber value="'.$question.'"></tr>');


}
print('<tr><td colspan=2><input type=submit name=submit value="Submit" ><input type=reset name=reset value="Clear" ></td></tr></table>');


print('</form>');

}
else
{

 echo "<div id='results'>Your result is:  $score%</div>";
print('<input type =hidden name=score value="'.$score.'">');
print('</form>');

}


?>

 

 

That's because instead of

print('<tr><td><input type="radio" name="answer" id="answer" value="'.$ranswer0.'">   '.$ranswer.'</td></tr>');

 

you should do

 

print('<tr><td><input type="radio" name="answer" id="answer" value="'.$answer[0].'">   '.$answer[0].'</td></tr>');

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.