1 Replies - 770 Views - Last Post: 02 November 2011 - 07:45 AM Rate Topic: -----

#1 oladimeji  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 02-November 11

want to display quiz answers from database in option button

Posted 02 November 2011 - 06:47 AM

please i need help in displaying quiz answers in an option button
this is what i currently i have and the answers are displaying directly but they cannot be selected
thanks in advance
  <?php
//connects to the database
  $host="localhost";  // Host name
  $username="****";   // Mysql username 
    $password="****";   // Mysql password 
	 $db_name="nigeriag_mytest";   // Database name 
	  $tbl_name="question_list";   // Table name 
	  // Connect to server and select database. 
	  mysql_connect("$host", "$username", "$password")or  die("cannot connect");
	    mysql_select_db("$db_name")or die("cannot select  DB");
		//$regnum="";
		//$fname=$_GET['fname'];
		$data = mysql_query("SELECT * FROM $tbl_name WHERE 1 ORDER BY RAND() LIMIT 1;") or die(mysql_error());
		print "<table border=0 cellpadding=1>";
		
		while ($info=mysql_fetch_array($data)) {
		
		print "<tr>";
		print "<th></th> <td>".$info['question']."</td>";
		print"</tr>";
		print "<tr>";
		print "<th></th> <td>".$info['opt1']."</td>";
		print "</tr>";
		print "<tr>";
        print "<th></th> <td>".$info['opt2']."</td>";
		print "</tr>";
		print "<tr>";
		print "<th></th> <td>".$info['opt3']."</td>";
		print "</tr>";
		print "<tr>";
		print "<th></th> <td>".$info['opt4']."</td>";
		print "</tr>";
		}	
		print"</table>";
		?>


This post has been edited by Dormilich: 02 November 2011 - 08:09 AM
Reason for edit:: removed login credentials


Is This A Good Question/Topic? 0
  • +

Replies To: want to display quiz answers from database in option button

#2 Jstall  Icon User is offline

  • Lurker
  • member icon

Reputation: 434
  • View blog
  • Posts: 1,042
  • Joined: 08-March 09

Re: want to display quiz answers from database in option button

Posted 02 November 2011 - 07:45 AM

You need to use a select tag. Instead of using <table> use <select> and instead of <tr>/<td> use <option>.

Instead of printing things out you could check out codeprada 's tutorial on using the DOM to populate a select box here.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1