Jump to content

How to display a numbered random output.. Help!!!!


tsuoshiro

Recommended Posts

Hi, i have a problem in numbering a random output... here is my code for the random process and output..

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<h3>Questions:</h3>
<table width="610" border="0">
<tr>
  <td height="60"><table width="610" border="0">
    <?php

require_once("mysql_connect.php");
$course=$_POST['course'];
$item=$_POST['item'];
$level=$_POST['level'];

if ($level=='easy')
{$insert_level="1";}

else if ($level=='average')
{$insert_level = "2";}

else 
{$insert_level="3";}

mysql_select_db ("cpedb",$connection);
$query = "SELECT * FROM `exam_question_mf` where `level`='$insert_level' AND `course`='$course' order by rand() limit $item";

$result=mysql_query($query,$connection) or die(mysql_error());
	 	  
	  //$switch=true;
	  while($row=mysql_fetch_array($result)) {

		 ?>
    <tr>
      <th colspan="2" scope="col"><div align="left"><<?php echo $row['question']; ?></div></th>
    </tr>
    <tr>
      <td width="235"><?php echo "A. " . $row['choice_a']; ?></td>
      <td width="359"><?php echo "C. " . $row['choice_a']; ?></td>
    </tr>
    <tr>
      <td height="60"><?php echo "B. " . $row['choice_b']; ?>
        <p> </p></td>
      <td><?php echo "D. " . $row['choice_d']; ?>
        <p> </p></td>
    </tr>
    <?php } ?>
  </table></td>
</tr>
</table>
</body>
</html>

 

Hope you can help me, i really need this for my project.. thank you in advance  :)

Link to comment
Share on other sites

I'm sorry if my question is not clear... Anyway my problem is that when i randomize my questions, i am generating a random of exam questions, there are no number beside it... for ex...

 

what is php?

a. program b.software c.food

 

there is no number beside it like this..

 

1.what is php?

a. program b.software c.food

 

 

hope this makes my questions clear... hope that you can help me...thanks again in advance  :)

Link to comment
Share on other sites

make a counter before the while loop

$result=mysql_query($query,$connection) or die(mysql_error());
$i = 1;	 	  
	  //$switch=true;
	  while($row=mysql_fetch_array($result)) {

		 ?>
    <tr>
      <th colspan="2" scope="col"><div align="left"><<?php echo $i.$row['question']; ?></div></th>
    </tr>
    <tr>

 

and increment it at the end of the loop

$i++;
}//end while

 

Link to comment
Share on other sites

Thank you so much... it works..

I would like to ask again, if you dont mind, like i said earlier i am generating a random questions.. i have a problem (again) on how to connect/combine the first random (test1) to the second random (test 2) questions.. its like combining/connecting/continuing the numbering of test 1 and test 2.

 

for example, for the easy category, there are 30 questions... i will connect it to the average category (let us say it contains 20 items).. how can i connect it...

hope my question is clear.. thanks again and hope you reply...

Link to comment
Share on other sites

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.