Jump to content

Paging problem


graham23s

Recommended Posts

Hi Guys,

 

i can't seem to see the error in my pagination code! its th elinks at th ebottom they dont seem to show next and previous!

 

<?php
  ###############################################
  # Pagination start
  ###############################################
  $page_number = $_GET['page-no'];
  
  if (intval($page_number) < 1)
  {
   $page_number = 1;
  }
    
  $max = 1; 
  $num = $page_number * $max - $max;  
  ###############################################
  # Pagination start
  ###############################################
  
  // grab the customers //
  $q_customers = "SELECT * FROM `fcp_customers`";
  $r_customers = mysql_query($q_customers) or die (mysql_error());
  $a_customers = mysql_num_rows($r_customers);
  
  // Pagination query
  $p_pagination = "SELECT * FROM `fcp_customers` LIMIT $num, $max";
  $r_pagination = mysql_query($p_pagination) or die (mysql_error());
  $a_pagination = mysql_num_rows($r_pagination);
  
  // start the table //
  print("<table width='95%' border='0' cellpadding='5' cellspacing='1' />\n");
  print("<tr>\n");
  print("<th>ID</th><th>First Name</th><th>Last Name</th><th>Registered</th><th>Last Login</th><th>Country</th><th>Action</th>\n");
  print("</tr>\n"); 
  print("<tr>\n");
  
  // while loop //
  while($row = mysql_fetch_array($r_pagination))
  {
  
           $cus_id = $row['id'];
        $cus_fname = $row['first_name'];
        $cus_lname = $row['last_name'];
      $cus_country = $row['country'];
     $cus_reg_date = $row['registered'];
   $cus_last_login = $row['last_logged_in'];
   
   // format the date //
   $cus_reg_pretty = date("F j, Y, g:i a", strtotime($cus_reg_date)); 
   $cus_last_login_pretty = date("F j, Y, g:i a", strtotime($cus_last_login)); 
   
   // include the coutry flags //
   include("inc/inc-flags.php");
   
  print("<td class=\"td_style\" align='left'>$cus_id</td><td class=\"td_style\" align='left'>$cus_fname</td><td class=\"td_style\" align='left'>$cus_lname</td><td class=\"td_style\" align='left'>$cus_reg_pretty</td><td class=\"td_style\" align='left'>$cus_last_login_pretty</td><td class=\"td_style\" align='center'>$flag</td><td class=\"td_style\" align='center'><a class='smart_links' href='admin.php?page=view_customers&customer_id=$cus_id'>View</a> | <a class='smart_links' href='admin.php?page=edit_customers&customer_id=$cus_id'>Edit</a> | <a class='smart_links' href='admin.php?page=delete_customer&customer_id=$cus_id'>Delete</a></td></tr>\n");
  
  }
  
  print("<tr>\n");
  print("<td colspan='7' class='td_style' align='right'>&nbsp</td>\n");
  print("</tr>\n");
  print("</table>");
  
  ###############################################
  # Pagination end
  ###############################################
  $totalpage     = ceil($a_pagination/$max) + 1;  
  $total_results = ceil($a_pagination/$max);
  
  $prevlink = ($page_number - 1);
  $nextlink = ($page_number + 1);

  // styling //
  print("<br /><div id='container'>");
  
  // previous link //
  if($page_number > 1) { 
        echo "<a class=\"page_links\" href=\"admin.php?page=customer_management&page-no=$prevlink\">Prev</a></span> \n"; 
  } 
    
  for($i = 1; $i < $totalpage; $i++)
  { 
    
    if ($i == $page_number) 
    { 
      echo "<span class=\"page_links\">$i</span> \n"; 
    } else { 
      echo "<a class=\"page_links\" href=\"admin.php?page=customer_management&page-no=$i\">$i</a></span> \n"; 
    } 
  } 

  if($page_number < $totalpage - 1) { 
        echo "<a class=\"page_links\" href=\"admin.php?page=customer_management&page-no=$nextlink\">Next</a></a>\n"; 
  }   
  
  print("</div><br />");
  ###############################################
  # Pagination end
  ###############################################
?>

 

a fresh set of eyes would be great!

 

cheers

 

Graham

Link to comment
https://forums.phpfreaks.com/topic/119051-paging-problem/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.