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
Share on other sites

The script i have does the pagination but i only want to display a set number of links.

When you have about 100 pages it looks rubbish when you have 100 page links.  I want to display about 6 per page so it looks like << Prev 50 51 52 53 53 Next >>
Link to comment
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.