Ravens PHP Scripts: Forums
 

 

View next topic
View previous topic
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> PHP
Author Message
bluehawk2506
New Member
New Member



Joined: Feb 07, 2006
Posts: 2
Location: Thailand

PostPosted: Tue Feb 07, 2006 12:24 pm Reply with quote

I have 4 radios buttons that you choose from for a test on one form and then at the bottom I have a Back button and a Next button, How Do I Make It So When You Click The Back Button It See What Radio Button that you were Checked and then click the Next button it still checked. And this my code.
Code:
<html>

<head>
   <title>Exam Online</title>
</head>
<body>
<div align=center>
<form action="<?=$PHP_SELF?>?Prev_Page=$Prev_Page&Next_Page=$Next_Page" method="post">
<?
   $conn = mysql_connect( $hostname, $username, $password );
   mysql_query("SET NAMES TIS620");
   if ( ! $conn )
      die( "Can't connect to MySQL" );
   mysql_select_db( $dbname, $conn )
      or die ( "Can't Select the $dbname" );

   $strSQL = "select * From lesson1 ";
   
   /* Set variable for a page */
   $Per_Page =1;
   if(!$Page)
   $Page=1;
   switch ($_POST['Page'])
   {
      case 'Back' :
         $Prev_Page = $Page-1;
         break;
      case 'Next' :
         $Next_Page = $Page+1;
         break;
   }

   $result = mysql_query($strSQL);
   $Page_start = ($Per_Page*$Page)-$Per_Page;
   $Num_Rows = mysql_num_rows($result);

   if($Num_Rows<=$Per_Page)
   $Num_Pages =1;
   else if(($Num_Rows % $Per_Page)==0)
   $Num_Pages =($Num_Rows/$Per_Page) ;
   else
   $Num_Pages =($Num_Rows/$Per_Page) +1;

   $Num_Pages = (int)$Num_Pages;

   if(($Page>$Num_Pages) || ($Page<0))
   print "<center><b>จำนวน $Page มากกว่า $Num_Pages ยังไม่มีข้อความ<b></center>";
   $strSQL .= " Where 1 Order by Number LIMIT $Page_start , $Per_Page";
   
   $result = mysql_query($strSQL);

   While($rs= mysql_fetch_array($result))
   {
      echo "<table cellpadding=\"4\" cellspacing=\"3\" border=\"1\" border width= \"65%\" align=\"center\" bgcolor=\"lavender\">
               <tr>
               <td>$rs[Number]."." $rs[Question]</td>
               </tr>\n";
?>
      <td><input type="radio" name="C$rs[0]" value="Choice1"> <?echo $rs[Choice1];?></td>
      </tr>
      <td><input type="radio" name="C$rs[0]" value="Choice2"> <?echo $rs[Choice2];?></td>
      </tr>
      <td><input type="radio" name="C$rs[0]" value="Choice3"> <?echo $rs[Choice3];?></td>
      </tr>
      <td><input type="radio" name="C$rs[0]" value="Choice4"> <?echo $rs[Choice4];?></td>
      </tr>
<?
      echo "<td align=\"center\"><img src=$rs[Pictures]></td>\n
      </tr>\n
      </table>";
   }
   echo "<table cellpadding=\"4\" cellspacing=\"3\" border=\"0\" border width= \"65%\" align=\"center\" bgcolor=\"lavender\">\n";
   /* Back Button */
   if($Prev_Page)
?>
   <td align="left"><input type="submit" name="Page" value="Back"></td>
   
<? /* Next Button */
   if($Page!=$Num_Pages)
?>
   <td align="right"><input type="submit" name="Page" value="Next"></td>
<?
   echo "</table>";
   mysql_close( $conn );
?>
</div>
</form>
</body>
</html>
Sad
 
View user's profile Send private message
evaders99
Former Moderator in Good Standing



Joined: Apr 30, 2004
Posts: 3221

PostPosted: Tue Feb 07, 2006 3:08 pm Reply with quote

You have to use the checked parameter on the radio

Code:


<input type="radio" name="whatever" value="whatever" checked>

_________________
- Star Wars Rebellion Network -

Need help? Nuke Patched Core, Coding Services, Webmaster Services 
View user's profile Send private message Visit poster's website
fkelly
Former Moderator in Good Standing



Joined: Aug 30, 2005
Posts: 3312
Location: near Albany NY

PostPosted: Tue Feb 07, 2006 3:30 pm Reply with quote

First I don't think the way you are trying to put out the submit buttons will work. Specifically in the code:
Code:
if($Prev_Page)

?>
<td align="left"><input type="submit" name="Page" value="Back"></td>

<? /* Next Button */
if($Page!=$Num_Pages)
?>
<td align="right"><input type="submit" name="Page" value="Next"></td>


It looks like you are trying to output a submit button with the value of Back if $Prev_Page is true and a value of Next if $Page doesn't equal the number of pages. But you end your PHP code with the ?> symbol so the td's for both submit buttons will be output without regard for the if statements (I think without having it to test). You need to echo those td's conditionally within the PHP section of your code if you only want to have one -- and I don't think you can have two submits with the same name and different values but I might be wrong about that.

Also it looks like you want your radio buttons to be an array by the way you are using "C$rs[0]" as their name. But they are intrinsically an array anyway and the four of them will be C$rs[0][0], C$rs[0][1], C$rs[0][2] and C$rs[0][3]. You could check if one was checked with the statement

Code:
if (form.C$rs[0][0].checked)


I believe.

It would be helpful if you told us what you are seeing from this code now. It sure doesn't look like it will work to me.
 
View user's profile Send private message Visit poster's website
bluehawk2506







PostPosted: Wed Feb 08, 2006 9:44 am Reply with quote

I'm sorry that my question is not clear. My program is examination that one question per page and have 4 choices when you choose some radio button then click the Next button for to do another question. And if you want to undo the previous question by click the Back button for correct the radio button that you choose but I want my program to show the radio button that you were choose it still checked. And when you click the Next button the radio button is still checked.
 
fkelly







PostPosted: Wed Feb 08, 2006 10:18 am Reply with quote

I'm sorry that I can't make much sense of this. From a "macro" point of view You appear to have a form that's wrapped in a div with some tables inside. But then you close the div first and the form second. That won't work. In addition the table where you have your radio buttons is inside a while loop so it will be echoed once for every "record" you find in the database. I can't see how that will work, the buttons will be writing over each other if it works at all. Then as I mentioned earlier it doesn't look to me like your php code will work , you have closed the php flow with ?> and then you output html that duplicates what is output slightly before (the submit buttons with the name "Page").

I can't duplicate it here without access to the database you are using and I wouldn't have time anyway. I think you might do better to find someone local to you who knows PHP and forms and have them sit down and work with you.

But if someone else here knows more than me and wants to help that's fine too.
 
Raven
Site Admin/Owner



Joined: Aug 27, 2002
Posts: 17088

PostPosted: Wed Feb 08, 2006 11:23 am Reply with quote

bluehawk2506 wrote:
I'm sorry that my question is not clear. My program is examination that one question per page and have 4 choices when you choose some radio button then click the Next button for to do another question. And if you want to undo the previous question by click the Back button for correct the radio button that you choose but I want my program to show the radio button that you were choose it still checked. And when you click the Next button the radio button is still checked.

Is this to cumulative? In other words, should the user be able to back-track from more than 1 page?
 
View user's profile Send private message
Display posts from previous:       
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> PHP

View next topic
View previous topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2007 phpBB Group
All times are GMT - 6 Hours
 
Forums ©