issso Posted October 5, 2007 Share Posted October 5, 2007 Hi everyone, I have been working on a pagination script for an online product catalog site I'm building. I'm having a problem with next and prev links, they're not working as they should I'm not getting the next set of results nor the previous, I keep getting the same page. Truly appreciate any help. Thanks issso --------------- Here's the test page: http://iz.myftp.org/eb/HTML/products3.php?cat=2&ppp=5 And the code is below: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>CATALOG</title> <script type="text/JavaScript"> function MM_jumpMenu(targ,selObj,restore){ //v3.0 eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'"); if (restore) selObj.selectedIndex=0; } </script> <link href="eb.css" rel="stylesheet" type="text/css" /> </head> <body> <? include("dbinfo.inc.php"); include("dbconnect.inc.php"); $catid = $_GET["cat"]; $max_results = $_GET["ppp"]; if(!isset($_GET['page'])){ $page = 1; } else { $page = $_GET['page']; } $from = (($page * $max_results) - $max_results); $sql = mysql_query("SELECT * FROM items LIMIT $from, $max_results"); $total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM items WHERE cat_id = '$catid'"),0); $total_pages = ceil($total_results / $max_results); $query="SELECT * FROM categories ORDER BY cat_name"; $result=mysql_query($query); $num=mysql_num_rows($result); $query2="SELECT * FROM categories where cat_id = '$catid'"; $result2=mysql_query($query2); $query3="SELECT * FROM items where cat_id = '$catid' limit $max_results"; $result3=mysql_query($query3); $num3=mysql_num_rows($result3); mysql_close(); $display = 2; $cols = 0; ?> <div align="center"> <div style="width:590px;"> <table style="width:590px; background-color:#f1f1f1; text-align:left;" cellpadding="0" cellspacing="0" border="0" valign="top"> <tr> <td align="left" valign="top"> <table cellpadding="0" cellspacing="0" border="0"> <tr> <td style="text-align:left;"> <img src="imgs/categories_prd.gif" width="152" height="30" /> </td> </tr> <tr> <td align="left"> <div style="margin: 5px 0 0 8px; width:142px; font-family:Arial, Helvetica, sans-serif; font-size:9pt; line-height:14pt;"> <? $i=0; while ($i < $num) { $cat_name=mysql_result($result,$i,"cat_name"); $cat_url=mysql_result($result,$i,"cat_url"); $cat_id=mysql_result($result,$i,"cat_id"); ?> <img src="imgs/bullet.gif" /><a href="products3.php?cat=<?echo $cat_id; ?>&ppp=5"><? echo $cat_name; ?></a><br/> <? $i++; } echo "<br />"; ?> </div> </td> </tr> </table> </td> <td style="width:383px; border: solid 1px #e6ded5;" valign="top"> <table width="377" cellspacing="0" cellpadding="0"> <tr> <td class="categorytitle" style="width:230px; height:30px; padding-left:8px; line-height:25px;"> <? $cat_name=mysql_result($result2,$i2,"cat_name"); echo $cat_name; ?> </td> <td align="right" style="width:119px; height:30px; font-family:Arial, Helvetica, sans-serif; font-size:10px; color:#6d615b; padding-left:8px; line-height:25px;"> <div style="float:right;"> <form name="results" id="results"> <select name="menu1" onchange="MM_jumpMenu('parent',this,0)"> <option value="">Pics per page</option> <option value="products3.php?cat=<?echo$catid;?>&ppp=5">5</option> <option value="products3.php?cat=<?echo$catid;?>&ppp=10">10</option> <option value="products3.php?cat=<?echo$catid;?>&ppp=15">15</option> </select> </form> </div> <td/> </tr> </table> <div align="center"> <img src="imgs/footer_line.gif" width="370" height="1" /> </div> <div align="right" style="text-align:right; font-family:Arial, Helvetica, sans-serif; font-size:11px; color:#6d615b;"> <? if($page > 1){ $prev = ($page - 1); echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$prev&cat=$catid&ppp=$max_results\"> Prev Page - </a> "; } for($i = 1; $i <= $total_pages; $i++){ if(($page) == $i){ echo "$i "; } else { echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$i&cat=$catid&ppp=$max_results\">$i</a> "; } } if($page < $total_pages){ $next = ($page + 1); echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$next&cat=$catid&ppp=$max_results\"> - Next Page</a>"; } ?> </div> <div style="margin: 10px 10px 0 10px; text-align:left; font-family:Arial, Helvetica, sans-serif; font-size:12px; color:#6d615b; line-height:18px;"> <? echo "<table width='350'>"; while($fetched = mysql_fetch_array($result3)){ if($cols == 0){ echo "<tr>\n"; } echo "<td style='width:162px; height:126px;' bgcolor=#e6ded5 align=center valign=middle>\n"; echo "<img src=".$fetched['item_img']." width=150 height=113></td>\n"; echo "<td style='width:10px;'><img src=imgs/clear.gif width='10px' height='10px'></td>"; $cols++; if($cols == $display){ echo "</tr>\n"; echo "<tr><td style='height=10px'><img src=imgs/clear.gif width='1px' height='10px'></td></tr>\n"; $cols = 0; } } if($cols != $display && $cols != 0){ $neededtds = $display - $cols; for($i=0;$i<$neededtds;$i++){ echo "<td></td>\n"; } echo "</tr></table>"; } else { echo "</table>"; } ?> </div> </td> <td style="width:20px; height:460px;" valign="bottom" background="imgs/bg.gif"> <img src="imgs/right_dropshdw.gif" /> </td> </tr> </table> </div> </div> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/72020-solved-pagination-and-jump-menu/ Share on other sites More sharing options...
JasonLewis Posted October 6, 2007 Share Posted October 6, 2007 double check that $page is being updated to the next page. echo it after you set it... so put it in like this: if(!isset($_GET['page'])){ $page = 1; } else { $page = $_GET['page']; } echo $page; put a few more echo statements in just to try and narrow down the problem. Quote Link to comment https://forums.phpfreaks.com/topic/72020-solved-pagination-and-jump-menu/#findComment-363208 Share on other sites More sharing options...
MadTechie Posted October 6, 2007 Share Posted October 6, 2007 Change $query3 to the follwoing $query3="SELECT * FROM items where cat_id = '$catid' LIMIT $from, $max_results"; Quote Link to comment https://forums.phpfreaks.com/topic/72020-solved-pagination-and-jump-menu/#findComment-363308 Share on other sites More sharing options...
JasonLewis Posted October 6, 2007 Share Posted October 6, 2007 on wat madtechie said, why do you have this query... $sql = mysql_query("SELECT * FROM items LIMIT $from, $max_results"); when it isnt even used any where else? looks like you wrote that query then wrote $query3 later on which does the same except selects only for a certain category. Quote Link to comment https://forums.phpfreaks.com/topic/72020-solved-pagination-and-jump-menu/#findComment-363314 Share on other sites More sharing options...
issso Posted October 6, 2007 Author Share Posted October 6, 2007 Thanks a lot guys, that did it! ProjectFear, I put the echo statement, and it's returning the correct page. But you were right about the $sql query, it wasn't used anywhere, and I was relying on it to give me the results limited by $from, $max_results MadTechie, thanks for your revised query, it works now and I deleted the $sql query. Here's the updated page: http://iz.myftp.org/eb/HTML/products3.php?cat=2&ppp=5 I knew there was mix up in my code, because I wrote each part of this seperatly, I did the jump menu first then I Was trying the pagination. Thanks a lot guys you were a great help. Regards Issso Quote Link to comment https://forums.phpfreaks.com/topic/72020-solved-pagination-and-jump-menu/#findComment-363376 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.