Daney11 Posted December 3, 2007 Share Posted December 3, 2007 Hey guys, This is both, PHP and HTML and is not getting on my nerves and im not sure how to crack it. It is to do with paginition. Snipplet of the code thats the problem: $pagination = '<table class="resultstable" width="508"><tr><td>'; /* Create a PREV link if there is one */ if($page > 1) { $pagination .= ' <a href="coverage.php?page='.$prev.'">Previous </a> '; } /* Loop through the total pages */ for($i = 1; $i <= $total_pages; $i++) { if(($page) == $i) { $pagination .= ''.$i.''; } else { $pagination .= ' <a href="coverage.php?page='.$i.'">'.$i.'</a> '; } } /* Print NEXT link if there is one */ if($page < $total_pages) { $pagination .= ' <a href="coverage.php?page='.$next.'">Next </a> </td></tr></table>'; } Now if i have 3 entrys in my database and i have limited the totalrows per page to 1 i should have 1 2 3 Next Previous 1 2 3 Next 1 2 3 Previous NOW THE PROBLEM 1 2 3 Next || Displays Perfect inside a box underneath. Previous 1 2 3 || Display Perfect inside the box underneath. 1 2 3 Previous || Totally breaks up my website. Now i know were the problem lies... // Starts The Box for the Pagination $pagination = '<table class="resultstable" width="508"><tr><td>'; //End The Box for Pagination if($page < $total_pages) { $pagination .= ' <a href="coverage.php?page='.$next.'">Next </a> </td></tr></table>'; } So as you can see, When the event Next is there the table closes. But when its "Previous 1 2 3" is there, there is no Next so the table cannot close so the table close needs to go for($i = 1; $i <= $total_pages; $i++) { if(($page) == $i) { $pagination .= ''.$i.'[b]</td></tr></table>[/b]'; } However, if placing the code there, the page breaks when both Next and Previous are in use. This has totally baffeled me. Any help would be great. Thanks guys Dane Quote Link to comment Share on other sites More sharing options...
Daney11 Posted December 3, 2007 Author Share Posted December 3, 2007 Im sure a simple if statement will work, somewhere, somehow? Quote Link to comment Share on other sites More sharing options...
Daney11 Posted December 3, 2007 Author Share Posted December 3, 2007 I know some of you was looking at this problem for a while and didnt reply. However i have it working now. All i needed to do was add a elseif for($i = 1; $i <= $total_pages; $i++) { if ($page == $i && $page == $total_pages) { $pagination .= '['.$i.']</td></tr></table>'; } elseif(($page) == $i) { $pagination .= '['.$i.']'; } else { $pagination .= ' <a href="coverage.php?page='.$i.'">'.$i.'</a> '; } } Quote Link to comment 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.