Jump to content

GOOGLE style paging


AdRock

Recommended Posts

Is it possible to edit this script so it displays like Google style paging where only a set number of page links are displayed at one time?

[code]<?
//REMEMBER TO CONNECT TO DATABASE!

include_once("includes/connection.php");

//**EDIT TO YOUR TABLE NAME, ECT.

$t = mysql_query("SELECT * FROM `events`");
  if(!$t) die(mysql_error());
   
$a                = mysql_fetch_object($t);
$total_items      = mysql_num_rows($t);
$limit            = $_GET['limit'];
$page             = $_GET['pagenum'];

//set default if: $limit is empty, non numerical, less than 1, greater than 50
if((!$limit)  || (is_numeric($limit) == false) || ($limit < 1) || ($limit > 50)) {
     $limit = 1; //default
}
//set default if: $page is empty, non numerical, less than zero, greater than total available
if((!$page) || (is_numeric($page) == false) || ($page < 0) || ($page > $total_items)) {
      $page = 1; //default
}

//calcuate total pages
$total_pages     = ceil($total_items / $limit);
$set_limit          = $page * $limit - ($limit);

//query: **EDIT TO YOUR TABLE NAME, ECT.

$q = mysql_query("SELECT id,title,content, DATE_FORMAT(eventdate, '%W %D %M %Y') as date, photo FROM events ORDER BY id DESC LIMIT $set_limit, $limit");
  if(!$q) die(mysql_error());
     $err = mysql_num_rows($q);
       if($err == 0) die("No matches met your criteria.");

//Results per page: **EDIT LINK PATH**

//show data matching query:
while($code = mysql_fetch_array($q)) {
    $EventDate = $code['eventdate'];
    echo "<h3>".$code['title']."</h3><p class='style3' style='text-align:left'><i>Event date: <b>".$code['date']."</b></i></p><p class=\"style3\"><img src=/images/".$code['photo']." align=\"right\" class=\"right\">".nl2br($code['content'])."</p><br>\n";
}

$id = urlencode($id); //makes browser friendly

//prev. page: **EDIT LINK PATH**

$prev_page = $page - 1;

if($prev_page >= 1) {
  echo("<b>&lt;&lt;</b> <a href=/events/$prev_page><b>Prev.</b></a>");
}

//Display middle pages: **EDIT LINK PATH**

for($a = 1; $a <= $total_pages; $a++)
{
   if($a == $page) {
      echo("<b> $a</b> | "); //no link
     } else {
  echo("  <a href=/events/$a> $a </a> | ");
     }
}

//next page: **EDIT THIS LINK PATH**

$next_page = $page + 1;
if($next_page <= $total_pages) {
   echo("<a href=/events/$next_page><b>Next</b></a> &gt; &gt;");
}

//all done
?>[/code]
Link to comment
https://forums.phpfreaks.com/topic/25744-google-style-paging/
Share on other sites

My guess would be all code will have a loop that goes through producing page links.

Just change this from a loop that outputs all links, starting with $i or similar as 0 and going to the end, to starting at $i = $current -3; and going to $ii = $current + 3; if that makes any sense?
Link to comment
https://forums.phpfreaks.com/topic/25744-google-style-paging/#findComment-118163
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.