Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    pph
    pph is offline
    New to the CF scene
    Join Date
    Jun 2007
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Angry pagination problem

    this code is working only first page, if i click next page its not working ,b'cos the values are not going to 2nd page for example
    page 1,2,3,...

    page 1 is working,but if click page 2 and 3 not working. my register_global is ON. what is the wrong in this code

    Code:
    <?php session_start(); 
    
    session_register("age1");
    session_register("age2");
    session_register("sex");
    session_register("findcountry");
    
    $age1=$_POST['age']; //comming from form
    $age2=$_POST['age2'];
    $sex=$_POST['gender1'];
    $findcountry=$_POST['country'];
    
    
    include("db.php");
    
    
    
    global $svrConn;
    global $country1;
    $country1=$findcountry;
    	$TotalToShow = 3;
    	$StartLimit = 0;
    	//$country1=$_SESSION['$findcountry'];
    
    	//$age1=16;
    	//$age2=45;
    	//$sex='Male';
    	//$findcountry='Sri Lanka';
    
    	if( isset($_GET['Total']) )
    		$TotalToShow = $_GET['Total'];
    		
    	if( isset($_GET['Start']) )
    		If( $_GET['Start'] < 0 )
    			$StartLimit = 0;
    		else
    			$StartLimit = $_GET['Start'];
    	
    	
    
    
    	if( $TotalToShow == 1 )
    	{
    		if( $StartLimit > 0 )
    			$Limit = $StartLimit;
    		else
    			$Limit = 1;
    	} else {
    		$Limit = $StartLimit . ", " . $TotalToShow;
    	}
    
    
    	// Query the database to find out how many records there is all up
    	
    	$qStr = "select * from penfriends where age>='".$_SESSION['age1']."' and age<='".$_SESSION['age2']."' and gender='".$_SESSION['sex']."' and country='".$_SESSION['findcountry']."'";
    	echo $qStr;
    	$NumRecords = mysql_num_rows(mysql_query($qStr));
    	
    	// divide the total number of records with the number to show per page
    	$TotalPages = (int)($NumRecords / $TotalToShow);
    	
    	// Check for any remaning records and if there is one the add
    	// another page to the list
    	$NumRemaning = $NumRecords % $TotalToShow;
    	if( $NumRemaning >= "1" )
    		$TotalPages++;
    	
    	
    	// New query to select all the data but only the number that was requested
    	$qStr = "select * from penfriends where age>='$age1' and age<='$age2' and gender='$sex' and country='$findcountry' ORDER BY lname DESC LIMIT " . $Limit . ";";
    	
    	// Get the results from the query
    	$result = mysql_query($qStr);
    	// count how many results were received
    	$NumRows = mysql_num_rows($result);
    
    $result = mysql_query($qStr);
    	
    	while($row = mysql_fetch_array($result))
      {
     
    	
    	?>
         <?php echo $row['fname'];
         echo $row['age'];
     echo $row['gender'];
       
    	   
     
      }
    	   if( $StartLimit != 0 )
    	{
    ?>
                <a href="<?php echo  $_SERVER['PHP_SELF'] ?>?age1=<?php echo $age1;?>&Total=<?php echo  $TotalToShow ?>&Start=<?php echo  ($StartLimit-$TotalToShow)?>">Previous</a> 
                <?php
    	} else {
    		echo "Previous ";
    	} /* if( $StartLimit != 0 ) */
    	
    	// show the page numbers
    	$NextStartPage = 0;
    	echo " ";
    	for( $x=0; $x < $TotalPages; $x++ )
    	{
    		if( $StartLimit == $NextStartPage )
    			echo ($x+1) . " ";
    		else   
    			echo "<a href=\"" . $_SERVER['SCRIPT_NAME'] . "?age1=".$_SESSION['age1']."&age2=".$_SESSION['age2']."&sex=".$_SESSION['sex']."&findcountry=".$_SESSION['findcountry']."&Total=" . $TotalToShow . "&Start=" . $NextStartPage . "\">" . ($x+1) . "</a> ";
    		
    		$NextStartPage = $NextStartPage+$TotalToShow;
    	}
    	
    	
    	// Show the Next Link
    	if( ($StartLimit + $TotalToShow) <= ($NumRecords - 1) )
    	{
    ?>
                <a href="<?php echo  $_SERVER['SCRIPT_NAME'] ?>?Total=<?php echo $TotalToShow ?>&Start=<?php echo  ($TotalToShow+$StartLimit) ?>">Next</a> 
                <?php
    	} else {
    		echo " Next";
    	} 
    ?>

  • #2
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,467
    Thanks
    8
    Thanked 1,085 Times in 1,076 Posts
    From a <form ... method="post">, you can use $_POST in your script,
    but from a URL ... <a href="myscript.php?var1=123&var2=123"> ...
    you need to use $_GET['var1'] instead of $_POST['var1']


  •  

    Posting Permissions

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