sharke Posted December 2, 2009 Share Posted December 2, 2009 Hi guys, i created basic function for pagination but i get incorect result. i mean this method must be outside ( $start = ($currentPage-1)*$count; ) for correct result (ORDER BY id DESC LIMIT ".$start.",".$res_per_page.") better solution <?php if (!isset($_GET['strana']) || !isnum($_GET['strana'])) { $_GET['strana'] = 0; } $res_per_page = 1; $result = mysql_query("SELECT COUNT(id) FROM comments"); $rows = mysql_result($result, 0); $result2 = mysql_query("SELECT * FROM comments ORDER BY id DESC LIMIT ".$_GET['strana'].",".$res_per_page.""); if ($rows > 1) { echo pagenav($_GET['strana'], $res_per_page, $rows); } function pagenav($start, $count, $total, $link = "") { global $PHP_SELF; if ($link == "") { $link = $PHP_SELF."?strana="; } //Determine total pages $totalPages = ceil($total/$count); $currentPage = $start; if ($currentPage < 1) { $currentPage = 1; } else if ($currentPage > $totalPages) { $currentPage = $totalPages; } $start = ($currentPage-1)*$count; //Create page navigation section $pageList = array();; if ($currentPage > 1) { $pageList[] = "<a href='".$link."1'><<</a>"; $pageList[] = "<a href='".$link.($currentPage-1)."'>< Previous Page</a>"; } for($page=1; $page<=$totalPages; $page++) { $pageList[] = ($currentPage==$page) ? "<b>[{$page}]</b>" : "<a href='".$link.$page."'>{$page}</a>"; } if ($currentPage < $totalPages) { $pageList[] = "<a href='".$link.($currentPage+1)."'>Next Page ></a>"; $pageList[] = "<a href='".$link.$totalPages."'><<</a>"; } $pageNav = implode(' ', $pageList); return "<div class='nav'>".$pageNav."</div>"; } Link to comment https://forums.phpfreaks.com/topic/183662-func-for-pagination-doesnt-work/ Share on other sites More sharing options...
rajivgonsalves Posted December 2, 2009 Share Posted December 2, 2009 I think your getting incorrect results due to this line if ($rows > 1) { echo pagenav($_GET['strana'], $res_per_page, $rows); } should be if ($rows > 1) { echo pagenav($_GET['strana'], $res_per_page, mysql_num_rows($result)); } Link to comment https://forums.phpfreaks.com/topic/183662-func-for-pagination-doesnt-work/#findComment-969443 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.