Jump to content

plz give me solution php code problem is radio values


hamedunisa

Recommended Posts

print('<form name=myform method="post" action="result.php">');

  if(isset($_GET['page']))

  $page=$_GET['page'];

  else

$page=1;

$rec=2;

$answers = array();

$question="";

$answerblock=array();

$rightanswer=array();

$offset=($page-1)*$rec;include("connection.php");

$q1="SELECT * FROM quiz ";

$t=mysql_query($q1);

$num_rows=mysql_num_rows($t);

$total_pages=ceil($num_rows/$rec);

$n=$offset+$rec;  

$i1=1;

if($_GET['page']==2){

 

 

$i=1*2;

$i1=$i;

}

if($_GET['page']==3){

$i=1*3;

$i1=$i;

}

  include("connection.php");

  $query="select * from quiz LIMIT  $offset,$rec";

$run=mysql_query($query);$num=mysql_num_rows($run);

while($row=mysql_fetch_array($run))

{

 

  $qid=$row['qid'];

$q=mysql_query("select * from exam_type_test where qustions=$qid ");

while($res=mysql_fetch_array($q)){ $qid1=$res['qustions'];  }?>

      <td width="230"><?php $i=$i1;  if($qid==$qid1){  echo "<br>";echo $i; echo".";echo $row['qustions']; }  $i1++; ?></td>

      <td width="73"> </td>

    </tr>

 

<tr><td></td><tr><?php include("connection.php");$q2=mysql_query("select * from exam_type_test where qustions=$qid");$row=mysql_fetch_array($q2);

 

$qid=$row[0];

$question=$row[1];

$answers[0]=$row[4];

$option[6]=$row[6];

$answers[1]=$row[5];

$answers[2]=$row[8];

$answers[3]=$row[9];

 

$answers[4]=$row[10];

 

$rightanswer=$row[4];

 

$answer0=$answers[0] ;

   

    $answer1=$answers[2] ;

      $answer2=$answers[3] ;

  $answer3=$answers[4] ;$option2=$option[6];

 

 

  // "'.$option_value.'" '.(($option_value == $_POST['option_choice'])?' checked="checked"':'').' ----value="'.$answer0 .'" '.(($answer0==$_POST[$option2])?'checked="checked"':'').'

 

session_start();

$mybuttons = array();

if(isset($_POST[$option2])) {

    foreach($_POST as $key => $value) {

        $mybuttons[$key][$value] = "checked";

    }

} elseif(isset($_SESSION['mybuttons'])) {

    echo $mybuttons = $_SESSION['mybuttons'];

 

}

$_SESSION['radio']=$table;

// echo "<form method='post' action='.$_SERVER['php_self'].'>";

 

print('<tr><td><input type="radio" name="'.$option2.'" value="'.$answer0 .'"'.$mybuttons[$option2][$answer0].' >   '.$answer0.'</td></tr>');

print('<tr><td><input type="radio" name="'.$option2.'" value="'.$answer1 .'"'.$mybuttons[$option2][$answer1].' >   '.$answer1 .'</td></tr>');

 

print('<tr><td><input type="radio" name="'.$option2.'" value="'.$answer2 .'"'.$mybuttons[$option2][$answer2].' >   '.$answer2 .'</td></tr>');

 

print('<tr><td><input type="radio" name="'.$option2.'" value="'.$answer3 .'"'.$mybuttons[$option2][$answer3].' >   '.$answer3 .'</td></tr>');

$_SESSION['mybuttons'] = $mybuttons; echo $table=$_POST['radio1'];

print('<tr><td> <input type=hidden name=rightanswer value="'.$table.'">');

?>

 

        </td>

</tr>

<?php  ?><?php } 

 

?>

 

<?php include("connection.php");

$pre=$page-1;

$next=$page+1;

if($page!=1)

{

 

echo "<a href='result.php?page=$pre'>Pre</a> |";

 

}

if($page!=$total_pages)

{

echo "<a href='result.php?page=$next'>Next</a> |";

 

 

}

 

 

?>

 

 

I retrive the questions and options in backend

 

i display perpage 1 or 3 questions next will be remaining question with options

 

i selected radio options each page finaly submit the result

 

i got a last page radio value only remaining values i did'nt get

 

i used sessions also

but it working or not i didn't get

 

 

plz solve this problem

So, (let me see if I'm correct) you're displaying 3 question perpage with with answers displayed as radio-buttons. You get to the last page, answer the questions on that page and click the "submit" button at which point they get inserted into a database.

 

But only the selected radio-buttons on the last page are inserted into the database and the selected radio-buttons from page 1 and 2 are not inserted into the database.

 

Is this correct?

Store the values in a $_SESSION variable as an array:

 

<?php
if(<THE_SUBMIT_BUTTON_IS_PRESSED (FOR EACH PAGE)>){
    $_SESSION['form_values'][] = $_POST['value1'];
    $_SESSION['form_values'][] = $_POST['value2'];
    $_SESSION['form_values'][] = $_POST['value3'];
}
?>

 

And then loop through those values when inserting them into the database:

<?php
while($value = $_SESSION['form_values']){
    //DATABASE "INSERT INTO" query
}
?>

 

It's not the full "done-for-you-and-ready-to-go" solution, but it should point you in the right direction.

total 3 questions each question 4 options

per page 2 question and click next page 3 question i selected radio button

 

 

when enter next page previous radio value not store

 

but i want to checked options store

 

where to user session array

Next |    <<<----cleck here go to "pre"                                                        --->  Pre |

 

                                                                            3.What is your shipping policy?

                                                                                        kjksjfkjsdkjf1

                                                                                            ece option

                                                                                          ece4 option

                                                                                        ece3 option

 

 

1.what is php?

  php is preposser

  multiple preprocesor

  kammala

  ajskdjfklsdjf

 

 

2.what is mvc?

  controll

  akjdkfjskljfkd

  EEEEgate

  adfkljklsdf

 

 

Finally Submit -->>

 

i selected 1 and  2 question also not display

 

answer

ece option

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.