how to display one question in each page in php?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • impin
    New Member
    • Jul 2010
    • 127

    #1

    how to display one question in each page in php?

    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.
    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 the above code:


    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

    how to make it?
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    Have it resubmit to the same page. Just add in a new parameter to pass between the page: the question number.

    Comment

    • raorafique
      New Member
      • Jun 2013
      • 3

      #3
      You can do this by submitting the question on the same page with query string as Question_ID.

      Comment

      • Claus Mygind
        Contributor
        • Mar 2008
        • 571

        #4
        Two ways I can think of
        1) create 3 <form> </form> on the main page. Add a submit button to each form. Each form would have a separate action.

        2) Just use a <input type="button" value="" onclick="" /> for each question. then in the onclick event handler just add a form.submit() with specific paramters.

        Comment

        Working...