rwc06 Posted September 2, 2008 Share Posted September 2, 2008 I am having difficulty with a pagination setup. It is pulling the info from the DB and has next and previous. When I click on next, the page is blank but there is data to make it populate. Can someone take a look and let me know what I am doing wrong? Below the code is the database structure if needed. <? $server = "localhost"; $userid = "xxx"; $pass = "xxx"; $database = "xxx"; $limit = 5; $con = mysql_connect("$server","$userid","$pass") or die ("Huh? What Server"); $db = mysql_select_db("$database",$con) or die("I said WHAT database"); if (empty($offset) || $offset < 0) { $offset=0; } if (empty($index)) $index=0; $getrows = mysql_query("select * from album", $con); $numrows=mysql_num_rows($getrows); $query = mysql_query("SELECT * from album, album_category where (album_category.album_category = '$category') and (album.album_catID = album_category.album_catID) limit $offset,$limit", $con); $num=1; while ($result=mysql_fetch_array($query)){ $num = ($num < 5 ? $num : 1); $index++; /* Increment the line index by 1 */ echo " <div class=thumbnail align=center> <a href='/displayimage.html?id=$result[albumID]'> <img border=0 alt='$result[album_category]' src=/images/gallery/BeachBBQ2007/thumbnails/$result[imagename]></a><br /><br /> </div> "; if ($num==3 && $index!=$numrows) $num++; } if ($numrows <= $limit) { } else { if ($offset!=0) { $prevoffset=$offset-$limit; echo "<br><a onMouseOver=\"window.status='Previous $limit Results'; return true\"; href=\"$PHP_SELF?offset=$prevoffset&index=$prevoffset\"><B>[Previous]</B></a> "; } else echo "<b>[Previous]</b> "; $pages = intval($numrows/$limit); if ($numrows%$limit) { $pages++; } for ($i=1;$i<=$pages;$i++) { if (($offset/$limit) == ($i-1)) { echo " <b>$i</b> "; } else { $newoffset=$limit*($i-1); echo " <a onMouseOver=\"window.status='Page $i Results'; return true\"; href=\"$PHP_SELF?offset=$newoffset&index=$newoffset\"><B>$i</B></a> \n"; } } if (!((($offset/$limit)+1)==$pages) && $pages!=1) { $newoffset=$offset+$limit; echo " <a onMouseOver=\"window.status='Next $limit Results'; return true\"; href=\"$PHP_SELF?offset=$newoffset&index=$newoffset\"><B>[Next]</B></a><p>\n"; } else echo " <b>[Next]</b>"; } mysql_close($con); ?> CREATE TABLE `album` ( `albumID` int(5) NOT NULL auto_increment, `imagename` varchar(50) NOT NULL default '', `album_catID` int(5) NOT NULL default '0', PRIMARY KEY (`albumID`) ) TYPE=MyISAM AUTO_INCREMENT=11 ; CREATE TABLE `album_category` ( `album_catID` int(5) NOT NULL default '0', `album_category` varchar(100) NOT NULL default '', PRIMARY KEY (`album_catID`) ) TYPE=MyISAM; Quote Link to comment https://forums.phpfreaks.com/topic/122418-help-with-pagination/ Share on other sites More sharing options...
webxan Posted September 2, 2008 Share Posted September 2, 2008 print the queries to the page and check if the $offset value are properly posted the the next page also execute the query in database to see if it actually fetches the result. to print query user "echo" Quote Link to comment https://forums.phpfreaks.com/topic/122418-help-with-pagination/#findComment-632197 Share on other sites More sharing options...
sasa Posted September 2, 2008 Share Posted September 2, 2008 where is variable $category is setup? Quote Link to comment https://forums.phpfreaks.com/topic/122418-help-with-pagination/#findComment-632300 Share on other sites More sharing options...
rwc06 Posted September 2, 2008 Author Share Posted September 2, 2008 It is on another page that is being passed Take a look if you can to see what the problem is http://www.robinwoodchurch.com/images/gallery/BeachBBQ2007/test1.php Quote Link to comment https://forums.phpfreaks.com/topic/122418-help-with-pagination/#findComment-632319 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.