Jump to content

php


sangeetha
 Share

Recommended Posts

 <?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

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

I don't understand what you're asking.

actually i am randomizing the id from a table
How 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 option
You 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

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

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...