Results 1 to 1 of 1

Thread: Pagination

  1. #1
    Join Date
    Sep 2011
    Posts
    35
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Question Pagination

    know the basic how to make the pagination or even i find the full code on internet but the problem is that i dont know how to use in form bases?
    I have online test quiz and each page showing one question and after press the next button showing the next question but if i want to show 5 question on one page and next page showing other 5 question how to make pagination for this situation? The code is mentioned below:
    Code:
    function hidediv()
    { 
    
    	var k=document.getElementById("totq").value;
    	
    	for(var j=2; j<=k; j++)
    	{
    	
    		var l="div"+j;
    		
    		document.getElementById(l).style.visibility="hidden";
    		document.getElementById(l).style.display="none";
    	}
    	document.getElementById('submitTest').style.visibility="hidden";
    	document.getElementById('submitTest').style.display="none";
    	
    }
    
    function nextq(qno)
    {
    var k=document.getElementById("totq").value;
    	for(var j=1; j<=k; j++)
    	{
    	if(j!=qno){
    		var l="div"+j;
    		document.getElementById(l).style.visibility="hidden";
    		document.getElementById(l).style.display="none";
    		}else{
    		var l="div"+j;
    		document.getElementById(l).style.visibility="visible";
    		document.getElementById(l).style.display="block";
    		
    		}
    	}
    	document.getElementById('submitTest').style.visibility="hidden";
    	document.getElementById('submitTest').style.display="none";
    	
    }
    
    function submitTest(){
    var k=document.getElementById("totq").value;
    	for(var j=1; j<=k; j++)
    	{
    	
    		var l="div"+j;
    		document.getElementById(l).style.visibility="hidden";
    		document.getElementById(l).style.display="none";	
    	}
    	document.getElementById('submitTest').style.visibility="visible";
    	document.getElementById('submitTest').style.display="block";
    	
    
    }
    the code is mentioned below where i called function:
    PHP Code:
    <form method="post" action="result_process.php" id="testForm" onSubmit="var ti=getCookie('timer').replace(':','.'); document.getElementById('timers').value=ti; return true"> 
    <input type="hidden" vaue="" id="timers" name="timeused"> 
    <?php 
    //echo "<pre>"; 
    //print_r($_POST); 
    //echo "</pre>"; 
    if(!isset($_COOKIE["test_id"])){ 
    $question_ids=explode("@",$question_ids); 
    $question_ids=implode(",",$question_ids); 

    else 

    $question_ids=explode("@",$_COOKIE['question_ids']); 
    $question_ids=implode(",",$question_ids); 

    $qids=substr($question_ids,1,strlen($question_ids)); 
    //echo $qids; 
    $questiondata=array(); 
    $result mysql_query("SET NAMES utf8"); 
    $result=mysql_query("select question,nob,q_option,additional,addi,submi from f_question where question_id in($qids) order by field(question_id,$qids) "); 
    while(
    $row=mysql_fetch_array($result)){ 
    $questiondata[]=$row


    foreach(
    $questiondata as $key=>$questiondata2){ 

    ?> 
    <div id="div<?php echo $key+1;?>"> 
    <?php 

    echo "Q ".($key+1).") "
    echo 
    $questiondata2['question']; 
    echo 
    "<br><br>"
    if(
    $questiondata2['submi']<="1"){ 
    $q_options=explode("@#",$questiondata2['q_option']); 
    srand((float)microtime() * 1000000); 
    shuffle($q_options); 

    $getarray array_slice($q_options04); 
    $i=0

                    foreach(
    $q_options as $q_options
                    { 
                        if(
    $questiondata2['submi']=="0"
                        { 
                        
    ?> 
            <input type="radio" name="ans<?php echo $key+1;?>" value="<?php echo $getarray[$i];?>" >&nbsp;&nbsp; <?php echo $getarray[$i]; echo "<br><br>"
                        } 
                        if(
    $questiondata2['submi']=="1"
                        { 
                        
    ?> 
            <input type="checkbox" name="ans<?php echo $key+1;?>[]" value="<?php echo $getarray[$i];?>" >&nbsp;&nbsp; <?php echo $getarray[$i]; echo "<br><br>"
                        } 

                    
    $i++; 
                    } 

    else 

    ?> 
    Answer: <input type="text" name="ans<?php echo $key+1;?>" size="30" value="" autocomplete="off" > 
    <?php 


    if(
    $questiondata2['addi']=="1"){ 
    if(
    $questiondata2['additional']!=""){ 
    echo 
    "<br><br><b>Additional information</b><br>".$questiondata2['additional']; 


      
     echo 
    "<br><br>"
    if((
    $key+1)>=2){?> 
    <input type="button" value="Back" onClick="nextq('<?php echo $key;?>')" > &nbsp;&nbsp; 
    <?php 

    if(isset(
    $_COOKIE['totq'])){ $totq=$_COOKIE['totq']; } 

    if((
    $key+1)<$totq){ 
    ?> 
    <input type="button" value="Next" onClick="nextq('<?php echo $key+2;?>')" > &nbsp;&nbsp; 
    <?php 


    ?> 
    <input type="button" value="Submit Test" onClick="submitTest()" > 
    <?php 

    echo "<br><br>"
    ?> 
    </div> 
    <?php 

    ?> 

    <div id="submitTest" > 
    <br><br>Do you really want to submit your test ?<br><br> 
    <input type="button" value="Cancel" onClick="nextq('<?php echo $key+1;?>')" > &nbsp;&nbsp;&nbsp; 
    <input type="submit" value="Submit"> 
    </div> 
    </form> 
    <input type="hidden" id="totq" value="<?php echo $key+1;?>" > 








    </div> 

    </td> 
    </tr></table> 
    </div>
    Last edited by salman1karim; 03-20-2012 at 06:08 AM.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •