shortysbest Posted May 30, 2011 Share Posted May 30, 2011 I have two button that load the next and previous pages of friends, I'm having trouble doing so, it sort of works, but it's got bugs so it's not right. Next: $query = mysql_query("SELECT * FROM friends WHERE (friend_1='".$id."' OR friend_2='".$id."') AND id>$last_id ORDER BY id ASC LIMIT 16"); previous: $query = mysql_query("SELECT * FROM friends WHERE (friend_1='".$id."' OR friend_2='".$id."') AND id<$last_id ORDER BY id ASC LIMIT 16"); $id = id of the users profile. $last_id = the last loaded friend id (unique id to friends table , not the friends actual id) Quote Link to comment Share on other sites More sharing options...
plznty Posted May 30, 2011 Share Posted May 30, 2011 http://www.phpfreaks.com/tutorial/basic-pagination Quote Link to comment Share on other sites More sharing options...
shortysbest Posted May 30, 2011 Author Share Posted May 30, 2011 I know how to paginate like that, was just hoping to be able to do it this way though Quote Link to comment Share on other sites More sharing options...
mikesta707 Posted May 31, 2011 Share Posted May 31, 2011 well, assuming you don't want to use the common pagination technique described in the tutorial linked in the first reply, what exactly is the problem? what happens when you click the next/previous button, and what do you expect to happen? Saying it "bugs out" isn't a sufficient description of the problem Quote Link to comment Share on other sites More sharing options...
shortysbest Posted May 31, 2011 Author Share Posted May 31, 2011 Well I've actually got it working pretty good now, however when I use the previous button it goes to the very first 16, not the last 16. $query = mysql_query("SELECT * FROM friends WHERE (friend_1='".$id."' OR friend_2='".$id."') AND id<$last_id ORDER BY id ASC LIMIT 16"); The only other problem is one I first load the page it isn't selecting the correct last_id loaded id, but after U click the forward/previous buttons once it fixes that. that's a javascript issue though. Quote Link to comment Share on other sites More sharing options...
mikesta707 Posted May 31, 2011 Share Posted May 31, 2011 you get the very first 16 because you order by the id in ascending order. You could order by descending order to get the most previous 16 Quote Link to comment Share on other sites More sharing options...
shortysbest Posted May 31, 2011 Author Share Posted May 31, 2011 yeah, I need to select the ids in DESC order, but order them by ASC order. I know that can be done, I'm just horrible with the more complex mYSQL Queries though, do you know? Quote Link to comment Share on other sites More sharing options...
mikesta707 Posted May 31, 2011 Share Posted May 31, 2011 I'm not sure if it would be possible to select the IDS in descending order, then reorder them in ascending order with just MySQL. If there is, I do not know the function or language construct that can do it. But MySQL isn't my strong point, so another poster more experienced in SQL may be able to give better advice Quote Link to comment Share on other sites More sharing options...
shortysbest Posted May 31, 2011 Author Share Posted May 31, 2011 I got a query that does it, however it is only loading a single record at a time :/ $query = mysql_query("SELECT B.* FROM (SELECT A.* FROM friends A WHERE (A.friend_1='".$id."' OR A.friend_2='".$id."') AND A.id<$last_id ORDER BY A.id DESC LIMIT 16) AS B ORDER BY B.id ASC"); Quote Link to comment 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.