sangeetha Posted February 16, 2008 Share Posted February 16, 2008 how to fetch a row from a table repeatedly one at a time and display in the same page and the page has radio button..the option is posted everytime when the user chooses the option and checked at the end Link to comment Share on other sites More sharing options...
jhecht Posted February 16, 2008 Share Posted February 16, 2008 <?php $msa = mysql_connect('localhost','user','pw') or die(mysql_error()); @mysql_select_db('yourDb',$msa) or die(mysql_error()); $sql = "SELECT * FROM table"; $ans = mysql_query($sql,$msa) or die(mysql_error()); while($row = mysql_fetch_assoc($ans)){ echo "<input type=\"radio\" name=\"radioButton\" value=\"".$row['idColumn']]."\" /> ".$row['TextColumn']." <br />"; } mysql_free_result($ans); mysql_close($msa); ?> Link to comment Share on other sites More sharing options...
sangeetha Posted February 19, 2008 Author Share Posted February 19, 2008 thank u...actually i am randomizing the id from a table.. for those id values, i have to fetch the result and display only one at an instance in the same page which has radio button option..i have to post the result to the next page in order to see the count of those radio buttons clicked..please help me to solve this problem..currently i m using a for loop for these purpose..for example if i am fetching all the result from table i can set limit as one and display...but now i couldn as i am using for loop for this. Link to comment Share on other sites More sharing options...
justsomeguy Posted February 19, 2008 Share Posted February 19, 2008 I don't understand what you're asking. actually i am randomizing the id from a tableHow do you randomize an ID from a table? Post the code where you do that.i have to fetch the result and display only one at an instance in the same page which has radio button optionYou only display one on the page? What do you mean by that? What are the radio button options?Please post all of the code you have, and say what you want it to do that it's not doing right now. Link to comment Share on other sites More sharing options...
jhecht Posted February 20, 2008 Share Posted February 20, 2008 for example if i am fetching all the result from table i can set limit as one and display...but now i couldn as i am using for loop for this.Thats extra work and strain on your MySQL server. use the LIMIT syntax built into MySQL, not a for loop. Link to comment Share on other sites More sharing options...
sangeetha Posted February 21, 2008 Author Share Posted February 21, 2008 I am doing project on online exam.here i want to randomize the questions with question id's.so i generated randomly id's from total 100 questions and which should be unique.i am taking this questions id's from the 'question' table. <?php do { $j=mt_rand(1,100); $a[$i]=$j; $i++; $k=array_unique($a); $n=count($k); }while($n<25); while(list($key,$value)= each($k)) { $e[$i]=$key; $z[$i]=$value; $i++; array_push($result,$value); }?> now i want to display only those questions in the exam page which contains one question with four options using radio buttons.here i have to calculate the marks scored for the correct answers when the students chooses the options.The answer is posted to same page.this page name is ran_display.php <?phpecho"<form name=f action=ran_display.php method=POST>"; ?> <? $random1=1;$p=1; for ($i=0; $i<$25; $i++) { $s=$result[$i]; $result1= mysql_query("select * from question where id='$s'" ); $row= mysql_fetch_array($result1); echo "<table border=0 width= 90% cellspacing=0>"; echo "<tr><td>$p</td>"; echo"<td>$row[quest]</td><tr>"; $opt1 = $row["opt1"]; $opt2 = $row["opt2"]; $opt3 = $row["opt3"]; $opt4 = $row["opt4"]; echo"<td ><input type=radio name=m value=\"$opt1\">$opt1</td><tr>"; echo"<td ><input type=radio name=m value=\"$opt2\">$opt2</td><tr>"; echo"<td ><input type=radio name=m value=\"$opt3\">$opt3</td><tr>"; echo"<td ><input type=radio name=m value=\"$opt4\">$opt4</td><tr>"; if ($random1== 25) { echo"<input name=checksub type=hidden value=no>"; echo "<td ><input type=submit onclick='return dothis();' value=End name=end>"; } else { echo"<input name=checksub type=hidden value=yes>"; echo"<td ><input type=submit name=submit onclick='return dothis();' value=NEXT><td><tr>"; }$random1++;$p++;}echo "</form>";?> here as i am taking random id's and fetching id's from here and there how can i display these 25 questions repeatedly on same page and calculate the marks... thanks..please do suggest me a solution for this Link to comment Share on other sites More sharing options...
justsomeguy Posted February 21, 2008 Share Posted February 21, 2008 You need to save the list of IDs so you can keep referring to the same list of questions. Link to comment Share on other sites More sharing options...
sangeetha Posted February 22, 2008 Author Share Posted February 22, 2008 saving means? can u say how it can be done... thanks in advance Link to comment Share on other sites More sharing options...
justsomeguy Posted February 25, 2008 Share Posted February 25, 2008 Saving means storing the list of IDs so that you can retrieve it later. You can save it in a database, a file, a cookie, or temporarily in the session. Link to comment Share on other sites More sharing options...
sangeetha Posted February 27, 2008 Author Share Posted February 27, 2008 Thank u very much.. I ve got my solution Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.