tsuoshiro Posted October 7, 2009 Share Posted October 7, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/176871-how-to-display-a-numbered-random-output-help/ Share on other sites More sharing options...
mikesta707 Posted October 7, 2009 Share Posted October 7, 2009 what is the problem you are having. if you describe the problem, it would be easier for someone to come up with a possible solution Quote Link to comment https://forums.phpfreaks.com/topic/176871-how-to-display-a-numbered-random-output-help/#findComment-932591 Share on other sites More sharing options...
tsuoshiro Posted October 7, 2009 Author Share Posted October 7, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/176871-how-to-display-a-numbered-random-output-help/#findComment-932601 Share on other sites More sharing options...
mikesta707 Posted October 7, 2009 Share Posted October 7, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/176871-how-to-display-a-numbered-random-output-help/#findComment-932605 Share on other sites More sharing options...
tsuoshiro Posted October 7, 2009 Author Share Posted October 7, 2009 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... Quote Link to comment https://forums.phpfreaks.com/topic/176871-how-to-display-a-numbered-random-output-help/#findComment-932617 Share on other sites More sharing options...
Philip Posted October 7, 2009 Share Posted October 7, 2009 Why not just use an ordered list in your html instead of tables? <ol><li>question</li></ol> Quote Link to comment https://forums.phpfreaks.com/topic/176871-how-to-display-a-numbered-random-output-help/#findComment-932628 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.