burge124 Posted April 9, 2008 Share Posted April 9, 2008 hi, i have a basic query along the lines of... <?php $con = mysql_connect("localhost","peter","abc123"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("my_db", $con); $result = mysql_query("SELECT * FROM Question"); while($row = mysql_fetch_array($result)) { echo $row['QuestionTitle'] . " " . $row['AnswerA']; echo "<br />"; } mysql_close($con); ?> is there any possibility of out putting a random selection, so that every time the page is viewed another question appears from database thanks Link to comment https://forums.phpfreaks.com/topic/100292-random-selection-from-database/ Share on other sites More sharing options...
zenag Posted April 9, 2008 Share Posted April 9, 2008 SELECT * FROM Question ORDER BY RAND() LIMIT 1 Link to comment https://forums.phpfreaks.com/topic/100292-random-selection-from-database/#findComment-512824 Share on other sites More sharing options...
burge124 Posted April 9, 2008 Author Share Posted April 9, 2008 thanks got that working, the query works fine but when i assign them to radio buttons they dont appear. <?php $result = mysql_query("SELECT * FROM question ORDER BY RAND() LIMIT 1"); while($row = mysql_fetch_array($result)) { echo $row['QuestionTitle']; echo "<br />"; } echo $row['CorrectAnswer']; echo "<br />"; ?> <INPUT TYPE="RADIO" NAME="question2"VALUE="answer2.1"><?php echo $row['AnswerA']; ?> <BR> <INPUT TYPE="RADIO" NAME="question2"VALUE="answer2.2"><?php echo $row['AnswerB']; ?> <BR> <INPUT TYPE="RADIO" NAME="question2" VALUE="answer2.3"><?php echo $row['AnswerC']; ?> <BR> Link to comment https://forums.phpfreaks.com/topic/100292-random-selection-from-database/#findComment-512844 Share on other sites More sharing options...
zenag Posted April 9, 2008 Share Posted April 9, 2008 try this....... if ($row['AnswerA']) { $check0 = " CHECKED"; } if ($row['AnswerB']) { $check1 = " CHECKED"; } if ($row['AnswerC']){ $check2 = " CHECKED"; } <INPUT TYPE="RADIO" NAME="question2"VALUE="answer2.1"<?php echo $check0 ;?> ><BR> <INPUT TYPE="RADIO" NAME="question2"VALUE="answer2.2"<?php echo $check1 ;?> ><BR> <INPUT TYPE="RADIO" NAME="question2" VALUE="answer2.3"<?php echo $check2 ; ?> ><BR> Link to comment https://forums.phpfreaks.com/topic/100292-random-selection-from-database/#findComment-512859 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.