Jump to content

Pagination -- numbering 12345...


runnerjp

Recommended Posts

How would i use the current code to output how i wish it to??

 

$pages = (floor($total/$entriesPerPage));
for($i=0;$i<$pages;$i++)
   echo "<P align=\"right\"> <a href=\"?page=$i\">[$i]</a></p> ";

 

I would like it to display at the right hand side of the page looking like this  [1]23456...  with the page the are on on [] and bold

Link to comment
Share on other sites

At the head or logic of your page (assumes $currentPage is set):

<?php

$totalPages = (ceil($total/$entriesPerPage));

$pageList = '';

for($page=1; $page<=$totalPages; $page++)
{
    if ($currentPage==$page)
    {
        $pageList .= " <b>[{$page}]</b> ";
    }
    else
    {
        $pageList .= " <a href="?page={$page}">{$page}</a> ";
    }
}

?>

 

In the body of your HTML

<P align="right"><?php echo $pageList; ?></p>

Link to comment
Share on other sites

all i get is 12  not [1] 2

 

here is full code

 

//Pagination variables
if (!isset($_GET['pagenum']))
   $_GET['pagenum'] = 0;
$entriesPerPage = 1;
$start = $_GET['pagenum']*$entriesPerPage;

//Querying
$query = "SELECT *, (SELECT COUNT(*) FROM photos WHERE thumb_id = 3) as total
              FROM photos
              WHERE thumb_id = 3
              LIMIT $start, $entriesPerPage";
$result = mysql_query($query) or die(mysql_error());
$total = mysql_result($result, 0, 'total');
$sql="SELECT * FROM `photos`  WHERE `thumb_id` = '3'";
$res = mysql_query($sql) or die(mysql_error());
//$pages = (floor($total/$entriesPerPage));
//for($i=0;$i<$pages;$i++)
   //echo "<P align=\"right\"> <a href=\"?page=$i\">[$i]</a></p> ";<?php

$totalPages = (ceil($total/$entriesPerPage));

$pageList = '';

for($page=1; $page<=$totalPages; $page++)
{
    if ($currentPage==$page)
    {
        $pageList .= " <b>[{$page}]</b> ";
    }
    else
    {
        $pageList .= " <a href=\"?page={$page}\">{$page}</a> ";
    }
}

echo $pageList; 
include 'albumphotos.php';



   
                       if ($_GET['pagenum'] != '') {
  $string .= "<div><table width=100%><tr><td>";
      if ($_GET['page'])
         $string .= "<center><a href=\"?pagenum=0\"><<</a> <a href=\"?pagenum=".($_GET['pagenum']-1)."\">< Previous Page</a></center>";
      $string .= "<td align=\"right\">";
      if ($_GET['pagenum']*$entriesPerPage+$entriesPerPage < $total)
         $string .= "<center><a href=\"?pagenum=".($_GET['pagenum']+1)."\">Next Page ></a> <a href=\"?pagenum=".(floor(($total-1)/$entriesPerPage))."\">>></a></center>";
      $string .= "</table></div>";

echo $string;
}

?>

Link to comment
Share on other sites

Your code is hard for me to follow, so i'm not going to try and decypher it. But, you never defined $currentPage as I stated needed to be done in my previous post. Or, you could have replaced it with $page looking at your code.

 

I'm assuming that the include file is what shows the current records. Here is a rewite of that page. No guarantees it will work since I did not test it.

 

<?php
$thumbID = 3;
$recordsPerPage = 1;

//Get total records
$query = "SELECT COUNT(*) as total
          FROM photos
          WHERE thumb_id = `{$thumbID}`";
$result = mysql_query($query) or die(mysql_error());
$totalRecords = mysql_result($result, 0, 'total');

//Determine total pages
$totalPages = ceil($totalRecords/$recordsPerPage);

//Determine current page
$currentPage = (int) $_GET['pagenum'];
if ($currentPage<1)
{
    $currentPage = 1;
}
else if ($currentPage>$totalPages)
{
    $currentPage = $totalPages;
}

//Get records for current page
$start = ($currentPage-1)*$recordsPerPage;
$query = "SELECT *
          FROM photos
          WHERE thumb_id = `{$thumbID}`
          LIMIT {$start}, {$recordsPerPage}";
$result = mysql_query($query) or die(mysql_error());

//Create page navigation section
$pageList = array();;

if ($currentPage>1)
{
    $pageList[] = "<a href="?pagenum=1"><<</a>";
    $pageList[] = "<a href="?pagenum=".($currentPage-1)."">< Previous Page</a>";
}

for($page=1; $page<=$totalPages; $page++)
{
    $pageList[] = ($currentPage==$page) ? "<b>[{$page}]</b>" : "<a href="?page={$page}">{$page}</a>";
}

if ($currentPage<$totalPages)
{
    $pageList[] = "<a href="?pagenum=".($currentPage+1)."">Next Page ></a>";
    $pageList[] = "<a href="?pagenum={$totalPages}"><<</a>";

}

$pageNav = implode(' ', $pageList);

//Show current records
include 'albumphotos.php';
?>                  

<div>
<table width="100%">
  <tr>
    <td>
    <?php echo $pageNav; ?>
    </td>
  </tr>
</table>
</div>

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.