widget Posted February 16, 2008 Share Posted February 16, 2008 I'm adding pagination to my site, so far most of the time its going fine but this one page has got me dumbfounded. The page displays a users items for sale in their virtual shop. Before it would just display them all on the one page, taking ages to load for users who had 100's of items for sale. Anyway, I got the pagination to work, although with it set to show 20 at a time it would only do the first 2 pages, nothing more. I could however manually edit the URL to show more items. If set to show 50 at a time it would only show the first page. I am using a shop with over 200 actual items, multiples of some items, total items is over 3000 What Ive had to do was change this line of code for it to work if ($query > ($start + 50)) { $nextThree = "<a href=usershop.php?game=1&user=$_GET[user]&start=$start2>Next</a>"; } else { $nextThree = "<a href=usershop.php?game=1&user=$_GET[user]&start=$start2>Next</a>"; } The problem is, after there are no more items, you can keep clicking NEXT and getting a blank page. Here is the code if (!$start) { $start = 0; } $start2 = $start + 50; $start3 = $start - 50; $query = mysql_query("SELECT * FROM usershops_items2 WHERE owner = '$find_owner[id]' AND price > '0' AND game = '$game' ORDER BY `usershops_items2`.`price` ASC LIMIT $start,50"); if ($query > ($start + 50)) { $nextThree = "<a href=usershop.php?game=1&user=$_GET[user]&start=$start2>Next</a>"; } else { $nextThree = "<a href=usershop.php?game=1&user=$_GET[user]&start=$start2>Next</a>"; } if (($start - 50) >= 0) { $previousThree = "<a href=usershop.php?game=1&user=$_GET[user]&start=$start3>Previous</a>"; } else { $previousThree = "Previous"; } $x = 0; print " <p align=center>$previousThree | $nextThree</p>"; while ($array = mysql_fetch_array($query)) { $get_item = fetch("SELECT * FROM items2 WHERE id = '$array[item_id]' AND game = '$game'"); $y = $x % 5; if ($y == 0) { echo "<tr>"; } if($get_item[retired] == "1"){ $rRetired = "<font color=grey>(retired)</font>"; }else{ $rRetired = ""; } if($array['price'] > 199999){ $err2 = "<font color=red>NOT BUYABLE</font>"; }else{ $err2 = ""; } echo "<td class='td1' OnMouseOver='this.className=\"td2\";' OnMouseOut='this.className=\"td1\";' onClick=\"if ( !confirm ('Are you sure you want to purchase this $get_item[item_name] for $array[price] $pointsVar?') ) { return false; } window.location='usershop.pro.php?game=$game&user=$user&id=$array[id]&price=$array[price]'\"><p align=center><img src=$base_url/images/user_images/opg_$game/items/item_$get_item[id].gif><br><font size=1><b>$get_item[item_name]</b><br>$array[stock] in Stock<br><br><font color='blue'>" . number_format($array[price]) . " $pointsVar</font><br>$rRetired<br>$err2</p></td>"; if ($y == 4) { echo "</tr>"; } $x++; } print "</table></center> </td> </tr> </table>"; print " <p align=center>$previousThree | $nextThree</p>"; Im guessing that as a user can have say 30 of the one item its somehow calculating from the total amount of items rather than calculating each item type as 1 I've tried numrows etc etc and havent had any success, any takers on how to fix this problem? PS. Im a newb to php so please reply like im a 5 year old lol Quote Link to comment https://forums.phpfreaks.com/topic/91369-i-know-how-much-everyone-loves-pagination-so/ Share on other sites More sharing options...
sasa Posted February 16, 2008 Share Posted February 16, 2008 try <?php if (!$start) { $start = 0; } $start2 = $start + 50; $start3 = $start - 50; $query = mysql_query("SELECT COUNT(*) FROM usershops_items2 WHERE owner = '$find_owner[id]' AND price > '0' AND game = '$game'"); $total_rows = mysql_result($query,0,0); $query = mysql_query("SELECT * FROM usershops_items2 WHERE owner = '$find_owner[id]' AND price > '0' AND game = '$game' ORDER BY `usershops_items2`.`price` ASC LIMIT $start,50"); if ($total_rows > ($start + 50)) { $nextThree = "<a href=usershop.php?game=1&user=$_GET[user]&start=$start2>Next</a>"; } else { $nextThree = " Next "; } if (($start - 50) >= 0) { $previousThree = "<a href=usershop.php?game=1&user=$_GET[user]&start=$start3>Previous</a>"; } else { $previousThree = "Previous"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/91369-i-know-how-much-everyone-loves-pagination-so/#findComment-468255 Share on other sites More sharing options...
widget Posted February 16, 2008 Author Share Posted February 16, 2008 sasa I love you, thanks so much!!! :D Arghh how do I mark this as solved? Quote Link to comment https://forums.phpfreaks.com/topic/91369-i-know-how-much-everyone-loves-pagination-so/#findComment-468268 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.