samy Posted March 11, 2008 Share Posted March 11, 2008 hello everyone. Need a little help on my code, im not far but still not be able to navigate trough recorset bar navigation.... the script who display images from a database... <?php require_once('Connections/dblink.php'); ?> <html> <head> <title>Galery</title> </head> <table> <?php $current_page = $_SERVER["PHP_SELF"]; $ImageDir = "images/"; $ImageThumb = $ImageDir . "thumbs/"; $limit=5; mysql_select_db($database_ligacaoDados, $ligacaoDados); $numresults = mysql_query("SELECT * FROM images"); $numrows=mysql_num_rows($numresults); // next determine if offset has been passed to script, if not use 0 if (empty($offset)) { $offset=0; } $getpic=mysql_query("select * from images LIMIT $offset, $limit"); while ($rows = mysql_fetch_array($getpic)) { extract($rows); echo "<tr>\n"; echo "<td><a href=\page.php?id=$image_id .\">"; echo "<img src=\"images/thumbs/". $image_id . ".jpg\" border=\"0\">"; echo "</a></td>\n"; echo "<td>" . $image_caption . "</td>\n"; echo "<td>" . $image_description . "</td>\n"; echo "<td>" . $image_date . "</td>\n"; echo "</tr>\n"; } // next we need to do the links to other results if ($offset>1) { // bypass PREV link if offset is 0 $prevoffset=$offset-5; print "<a href=\"$current_page?offset=$prevoffset\">PREV</a> \n"; } // calculate number of pages needing links $pages=intval($numrows/$limit); // $pages now contains int of pages needed unless there is a remainder from division if ($numrows%$limit) { // has remainder so add one page $pages++; } for ($i=1;$i<=$pages;$i++) { // loop thru $newoffset=$limit*($i-1); print "<a href=\"$current_page?offset=$newoffset\">$i</a> \n"; } // check to see if last page if (!(($offset/$limit)==$pages) && $pages!=1) { // not last page so give NEXT link $newoffset=$offset+$limit; print "<a href=\"$current_page?offset=$newoffset\">NEXT</a><p>\n"; } ?> </table> </body> </html> everything works exept that i can't navigate trough the recorset (prev 1234 next)....did i miss something on my tutorial? could someone kindly give a kick on my code? in advance thank you best regards Sam Quote Link to comment https://forums.phpfreaks.com/topic/95582-question-about-pagination/ Share on other sites More sharing options...
r-it Posted March 11, 2008 Share Posted March 11, 2008 heres a tutorial i uploaded for you: http://www.byo.co.za/Pagination_with_PHP.doc Quote Link to comment https://forums.phpfreaks.com/topic/95582-question-about-pagination/#findComment-489319 Share on other sites More sharing options...
sasa Posted March 11, 2008 Share Posted March 11, 2008 put if(isset($_GET['offset'])) $offset = $_GET['offset']; near the top of script Quote Link to comment https://forums.phpfreaks.com/topic/95582-question-about-pagination/#findComment-489426 Share on other sites More sharing options...
samy Posted March 11, 2008 Author Share Posted March 11, 2008 ooh i'am a happy newbie thanks a lot for your help! if is not too much to ask for what purpose it is needed the code you give me? thanks a lot. sam Quote Link to comment https://forums.phpfreaks.com/topic/95582-question-about-pagination/#findComment-489566 Share on other sites More sharing options...
sasa Posted March 11, 2008 Share Posted March 11, 2008 when you pass variabl with URL in array $_GET is value of passed variable Quote Link to comment https://forums.phpfreaks.com/topic/95582-question-about-pagination/#findComment-489699 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.