Dave2711 Posted July 30, 2009 Share Posted July 30, 2009 Hi guys, ive been using a few guides to do pagination.. most of which I couldn't get to work atall.. and now ive got to one which works, except when I change pages it loads the same images on the page as it did before. Just wondering if anyone can point me in the right direction about fixing this? <?php include('includes/header.php'); include('includes/sq-config.php'); ?> <img src="images/images.jpg"> <br><br> <table width="95%" align="center" cellpadding="5" background="images/bg.gif"> <tr> <td> <? if (!(isset($pagenum))) { $pagenum = 1; } $data = mysql_query("SELECT * FROM img") or die(mysql_error()); $rows = mysql_num_rows($data); $page_rows = 10; $last = ceil($rows/$page_rows); if ($pagenum < 1) { $pagenum = 1; } elseif ($pagenum > $last) { $pagenum = $last; } $max = 'limit ' .($pagenum - 1) * $page_rows .',' .$page_rows; $data_p = mysql_query("SELECT * FROM img $max") or die(mysql_error()); while($info = mysql_fetch_array( $data_p )) { echo "<tr><td><a href=pic.php?id=" . $info['id'] . ">"; echo "<img width=100 height=100 src=uploads/" . $info['img_dir'] . "></a></td>"; echo "<td padding=2 bgcolor=ffffff><a href=pic.php?id=" . $info['id'] . ">"; echo "<b>" . $info['img_nme'] . "</b></a>"; echo "<br>" . $info['img_dsc'] . "</td></tr>"; } echo "</td></tr></table>"; echo "Page $pagenum of $last <b>"; if ($pagenum == 1) { } else { echo "<td><a href='{$_SERVER['PHP_SELF']}?pagenum=1'>«« First</a> "; echo " "; $previous = $pagenum-1; echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$previous'>« Previous</a>"; } echo " "; if ($pagenum == $last) { } else { $next = $pagenum+1; echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$next'>Next »</a> "; echo " "; echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$last'>Last »»</a> "; } ?> <? include('includes/footer.php'); ?> Link to comment https://forums.phpfreaks.com/topic/168129-pagination-help-please/ Share on other sites More sharing options...
phpSensei Posted July 30, 2009 Share Posted July 30, 2009 I wont even help you because you used short tags.. <? to <?php please hmph Link to comment https://forums.phpfreaks.com/topic/168129-pagination-help-please/#findComment-886710 Share on other sites More sharing options...
Dave2711 Posted July 30, 2009 Author Share Posted July 30, 2009 Sorrrrrry bad habits lol <?php include('includes/header.php'); include('includes/sq-config.php'); ?> <img src="images/images.jpg"> <br><br> <table width="95%" align="center" cellpadding="5" background="images/bg.gif"> <tr> <td> <?php if (!(isset($pagenum))) { $pagenum = 1; } $data = mysql_query("SELECT * FROM img") or die(mysql_error()); $rows = mysql_num_rows($data); $page_rows = 10; $last = ceil($rows/$page_rows); if ($pagenum < 1) { $pagenum = 1; } elseif ($pagenum > $last) { $pagenum = $last; } $max = 'limit ' .($pagenum - 1) * $page_rows .',' .$page_rows; $data_p = mysql_query("SELECT * FROM img $max") or die(mysql_error()); while($info = mysql_fetch_array( $data_p )) { echo "<tr><td><a href=pic.php?id=" . $info['id'] . ">"; echo "<img width=100 height=100 src=uploads/" . $info['img_dir'] . "></a></td>"; echo "<td padding=2 bgcolor=ffffff><a href=pic.php?id=" . $info['id'] . ">"; echo "<b>" . $info['img_nme'] . "</b></a>"; echo "<br>" . $info['img_dsc'] . "</td></tr>"; } echo "</td></tr></table>"; echo "Page $pagenum of $last <b>"; if ($pagenum == 1) { } else { echo "<td><a href='{$_SERVER['PHP_SELF']}?pagenum=1'>«« First</a> "; echo " "; $previous = $pagenum-1; echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$previous'>« Previous</a>"; } echo " "; if ($pagenum == $last) { } else { $next = $pagenum+1; echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$next'>Next »</a> "; echo " "; echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$last'>Last »»</a> "; } ?> <?php include('includes/footer.php'); ?> Hows that? Link to comment https://forums.phpfreaks.com/topic/168129-pagination-help-please/#findComment-886714 Share on other sites More sharing options...
phpSensei Posted July 30, 2009 Share Posted July 30, 2009 thanks try this <?php include('includes/header.php'); include('includes/sq-config.php'); ?> <img src="images/images.jpg"> <br><br> <table width="95%" align="center" cellpadding="5" background="images/bg.gif"> <tr> <td> <?php if(!isset($pagenum)){ $pagenum = 1; } $data = mysql_query("SELECT * FROM img") or die(mysql_error()); $rows = mysql_num_rows($data); $page_rows = 10; $last = ceil($rows/$page_rows); if ($pagenum < 1){ $pagenum = 1; } elseif ($pagenum >= $last){ $pagenum = $last; } $max = 'limit ' .($pagenum - 1) * $page_rows .',' .$page_rows; $data_p = mysql_query("SELECT * FROM img $max") or die(mysql_error()); $next = $pagenum+1; while($info = mysql_fetch_array( $data_p )) { echo "<tr><td><a href=pic.php?id=" . $info['id'] . ">"; echo "<img width=100 height=100 src=uploads/" . $info['img_dir'] . "></a></td>"; echo "<td padding=2 bgcolor=ffffff><a href=pic.php?id=" . $info['id'] . ">"; echo "<b>" . $info['img_nme'] . "</b></a>"; echo "<br>" . $info['img_dsc'] . "</td></tr>"; } echo "</td></tr></table>"; echo "Page $pagenum of $last <b>"; if ($pagenum == 1) { } else { echo "<td><a href='{$_SERVER['PHP_SELF']}?pagenum=1'>«« First</a> "; echo " "; $previous = $pagenum-1; echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$previous'>« Previous</a>"; } echo " "; if ($pagenum == $last) { } else { echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$next'>Next »</a> "; echo " "; echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$last'>Last »»</a> "; } ?> <?php include('includes/footer.php'); ?> Link to comment https://forums.phpfreaks.com/topic/168129-pagination-help-please/#findComment-886715 Share on other sites More sharing options...
Dave2711 Posted July 30, 2009 Author Share Posted July 30, 2009 No still no luck, it knows how many pages there should be.. but it just seems to fetch the same data, also the links dont change so although its changing the URL adding pagenum=2, its still showing the Next/Last links, I dont understand it haha.. probably something stupid i've missed. Link to comment https://forums.phpfreaks.com/topic/168129-pagination-help-please/#findComment-886722 Share on other sites More sharing options...
phpSensei Posted July 30, 2009 Share Posted July 30, 2009 you forgot $_GET['pagenum']; its always going to be the same lol cause theres no HTTP GET VAR. try <?php include('includes/header.php'); include('includes/sq-config.php'); ?> <img src="images/images.jpg"> <br><br> <table width="95%" align="center" cellpadding="5" background="images/bg.gif"> <tr> <td> <?php $pagenum = $_GET['pagenum']; if(!isset($pagenum)){ $pagenum = 1; } $data = mysql_query("SELECT * FROM img") or die(mysql_error()); $rows = mysql_num_rows($data); $page_rows = 10; $last = ceil($rows/$page_rows); if ($pagenum < 1){ $pagenum = 1; } elseif ($pagenum >= $last){ $pagenum = $last; } $max = 'limit ' .($pagenum - 1) * $page_rows .',' .$page_rows; $data_p = mysql_query("SELECT * FROM img $max") or die(mysql_error()); $next = $pagenum+1; while($info = mysql_fetch_array( $data_p )) { echo "<tr><td><a href=pic.php?id=" . $info['id'] . ">"; echo "<img width=100 height=100 src=uploads/" . $info['img_dir'] . "></a></td>"; echo "<td padding=2 bgcolor=ffffff><a href=pic.php?id=" . $info['id'] . ">"; echo "<b>" . $info['img_nme'] . "</b></a>"; echo "<br>" . $info['img_dsc'] . "</td></tr>"; } echo "</td></tr></table>"; echo "Page $pagenum of $last <b>"; if ($pagenum == 1) { } else { echo "<td><a href='{$_SERVER['PHP_SELF']}?pagenum=1'>«« First</a> "; echo " "; $previous = $pagenum-1; echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$previous'>« Previous</a>"; } echo " "; if ($pagenum == $last) { } else { echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$next'>Next »</a> "; echo " "; echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$last'>Last »»</a> "; } ?> <?php include('includes/footer.php'); ?> Link to comment https://forums.phpfreaks.com/topic/168129-pagination-help-please/#findComment-886725 Share on other sites More sharing options...
Dave2711 Posted July 30, 2009 Author Share Posted July 30, 2009 Ahhh, your a star haha.. been fidling about for hours trying to get that working thanks so much! Atleast I know for next time now Thanks again Link to comment https://forums.phpfreaks.com/topic/168129-pagination-help-please/#findComment-886726 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.