runnerjp Posted November 4, 2009 Share Posted November 4, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/180333-pagination-numbering-12345/ Share on other sites More sharing options...
Mchl Posted November 4, 2009 Share Posted November 4, 2009 Where's the information on which page is the current one? Quote Link to comment https://forums.phpfreaks.com/topic/180333-pagination-numbering-12345/#findComment-951279 Share on other sites More sharing options...
Psycho Posted November 4, 2009 Share Posted November 4, 2009 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> Quote Link to comment https://forums.phpfreaks.com/topic/180333-pagination-numbering-12345/#findComment-951281 Share on other sites More sharing options...
runnerjp Posted November 4, 2009 Author Share Posted November 4, 2009 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; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/180333-pagination-numbering-12345/#findComment-951288 Share on other sites More sharing options...
Psycho Posted November 4, 2009 Share Posted November 4, 2009 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> Quote Link to comment https://forums.phpfreaks.com/topic/180333-pagination-numbering-12345/#findComment-951329 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.