Web Analytics Made Easy -
StatCounter Pagination Problem - CodingForum

Announcement

Collapse
No announcement yet.

Pagination Problem

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Resolved Pagination Problem

    Code:
    <?php require_once('includes/connection.php') ?>
    <?php require_once('includes/functions.php') ?>
    <?php include('includes/header.php') ?>
    <?php include('includes/sidebar.php') ?>
    	<div id="contentnorightbar">		
    		<h2 id="Intro"><a href="#">Registered Partners</a></h2>
    <?php	
    	
    	//Check if there is a page number
    	if (!(isset($pagenum)))
    	{
    		$pagenum = 1;
    	}
    
    	$data = "SELECT * FROM partner";
    	$result = mysql_query($data, $connection) or die(mysql_error());
    
    
    	//check for number of rows
    	$rows = mysql_num_rows($result);
    	//set no. of rows to display per page
    	$page_rows = 3;
    	//find last page number
    	$last = ceil($rows/$page_rows);
    	//this if statment will see that the page number is exact the max, not 1 below nor 1 above
    	if ($pagenum < 1)
    	{
    		$pagenum =1;
    	} elseif ($pagenum > $last)
    	{
    		$pagenum = $last;
    	}
    	$max = 'LIMIT ' .($pagenum - 1) * $page_rows . ',' .$page_rows;
    
    		if ($result) {
    			//If the Query succeed
    			print "<br /><table class='partners' border='1' cellpadding='0' cellspacing='0' width='100%'>
    					<tr>
    					<th>User</th>
    					<th>Name</th>
    					<th>Company</th>
    					<th>E-mail</th>
    					<th>Mobile</th>
    					<th>Edit</th>
    					</tr>";
    					$data_p = mysql_query("SELECT * FROM partner $max") or die(mysql_error());
    					
    			while($info = mysql_fetch_array($data_p)) {				
    				if($i%2 == 0)
    				{
    				print "<tr bgcolor='#FFF'>";
    				$i++;
    				}
    				else {
    				print "<tr bgcolor='#EFF8FF'>";
    				$i++;
    				}
    				print "<td>" . $info['username'] . "</td>";
    				print "<td>" . ucfirst($info['firstname']) . " " . ucfirst($info['lastname']) .  "</td>";
    				print "<td>" . $info['orgname'] . "</td>";
    				print "<td>" . $info['email'] . "</td>";
    				print "<td>" . $info['mobile'] . "</td>";
    				print "<td><a href='../ipms/edit_partner.php?username={$info['username']}'>Edit</a></td></tr>";
    			}
    			print "</table>";
    			echo " <br /> ";
    			echo " --Page $pagenum of $last-- ";
    			
    		} else {
    			//Display error message
    			echo "<p>Query failed. </p>";
    			echo mysql_error();
    		}
    	if ($pagenum == 1)
    			{
    
    			} else {
    				$next = $pagenum+1;
    				echo "<a href='{$_SERVER['PHP_SELF']}?pagenum=1'> <<-First</a> ";
    				echo " ";
    				$previous = $pagenum-1;
    				echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$previous'><-Previous</a> ";
    			}
    			echo " <div align=\"right\"> ";
    		if ($pagenum == $last)
    		{
    		}
    		else {
    		$next = $pagenum+1;
    		echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$next'>Next -></a> ";
    		echo " ";
    		echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$last'>Last ->></a> ";
    } 
    ?>
    </div>
    	</div>	
    <?php include('includes/footer.php') ?>
    The First Page is working fine, but from the second page onwards it isn't.
    Last edited by ashwinnaidu; Apr 6, 2009, 07:53 AM.

  • #2
    Are you assigning $_GET['$pagenum'] to your $pagenum? Or Is the register_globals turned On(I don't recommend to do this)?
    Digitalocean Cloud Hosting (Referral link - get $10 free credit) Fameco

    Comment


    • #3
      I haven't changed any default settings.

      Comment


      • #4
        Default settings? Isn't it your code?
        Digitalocean Cloud Hosting (Referral link - get $10 free credit) Fameco

        Comment


        • #5
          I was talking about the default settings in the php.ini file.
          BTW, could you please tell me about register_globals and why is it not recommended ?

          Comment


          • #6
            Try to follow the http://php.net/register_globals
            Digitalocean Cloud Hosting (Referral link - get $10 free credit) Fameco

            Comment

            Working...
            X