2

i have a code that display 3 questions and multiple answers from database for user to select. after choosing the answers user will hit the submit button. its works fine.

Current Code:

<?php

$today=date("Y-m-d");

echo "<form method='post' id='submit' action='checkresult.php' dir='rtl'>";
$sql="SELECT * FROM cquestions where showdate='$today' limit 3";
$result=mysql_query($sql);


while ($row = mysql_fetch_array($result)) {
   echo "<p>" . $row['cqtext'] . "</p>";
   $sql2="SELECT * FROM canswers where cqid=".$row['cqid'];
   $result2=mysql_query($sql2);
   while($row2=mysql_fetch_assoc($result2))
   {
      echo "<input type='radio' name='".$row['cqid']."' value='".$row2['cqans']."' />".$row2['aatext']; 
   }
}


$tomorrow= date("Y-m-d", strtotime("tomorrow"));
$sql4="SELECT * FROM qupdate";
$result4=mysql_query($sql4);
$last_update=mysql_result($result4,"last_update");
if($last_update==$today)
{
    $cqid=mysql_result($result,"cqid");
    $update1="update cquestions set showdate='$tomorrow' where showdate='0000-00-00' and cqid!='$cqid' order by cqid limit 3";
    mysql_query($update1);
    $update2="update qupdate set last_update='$tomorrow'";
    mysql_query($update2);
    $sql3="SELECT * FROM qupdate";
    $result3=mysql_query($sql3);
    $last_update=mysql_result($result3,"last_update");  
}

echo"<br>";
echo"<br>";
echo"<input type='submit' id='submit' name='submit' value='Submit Answers' />";
echo "</form>" ;
?>

Output of above code

question1
ans1, ans2, ans3, ans4

question2
ans1, ans2, ans3, ans4

question3
ans1, ans2, ans3, ans4

SUBMIT

i want make some changes. i want to make it to display 1st question in first page, and user clicks next then it must go to 2nd question, then 3rd question and finally submit button.

Expecting Output

page1
Question 1
ans1, ans2, ans3, ans4

Next

after choosing the ans user clicks next
page2
question 2
ans1, ans2, ans3, ans4

Next

page3
question 3
ans1, ans2, ans3, ans4

SUBMIT Button.

how to do it?

1
  • hi DevZer0! paging..?! i am new to php. could you help me? how to do it? Commented Jun 16, 2013 at 9:54

3 Answers 3

1

You can do it with jquery show/hide or fadeIn/fadeOut like

<form>
<div id="question1" class="questions">
//php question and its answers in radio
<a href="javascript:void(0)" onclick="getnext('question2')"></a>
</div>
<div id="question2" class="questions" style="display:none">
//php question and its answers in radio
<a href="javascript:void(0)" onclick="getnext('question3')"></a>
</div>
<div id="question3" class="questions" style="display:none">
//php question and its answers in radio
<input type="submit"/>
</div>


<script type="text/javascript">
function getnext(id){
//for fade effect
$(".questions").fadeOut("fast");
$("#"+id).fadeIn("slow");
//for show/hide
$(".questions").hide();
$("#"+id).show();
 }
 </script>

Make sure you have included jquery

Sign up to request clarification or add additional context in comments.

Comments

0

In HTML

at end of page one:

<a href="?gotopage=2">Next</a>

And

at end of page two:

<a href="?gotopage=3">Next</a>

And

at end of page three:

<a href="?dosubmit">Submit</a>

In PHP

if( isset($_GET['gotopage'])  && $_GET['gotopage'] == 2 ){
   //codes for 2 page
} 

And so on...

1 Comment

hi EmRa228? how to alter my current code? now i am displaying 3 rows of data. so now i want to display single row in each page? for example , for second page i have to display only the second row from table?
0

Paging is a simple concept where each record is written to a that shows as a page, and has links that traverse toward other pages that has other record data ..

Reference: Simple and easy PHP pagination

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.