Jump to content

Next 16 friends, and previous 16 friends mysql query help


shortysbest

Recommended Posts

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)

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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");

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.