Jump to content

Recommended Posts

is there a way I can grab the previous and future ID in a mysql database.

 

 

i.e.

 

USERID |

8            |

9            |

10          |

 

 

Dispaying Info for user 9

lorem ipsum

 

<Prev                        Next>

 

 

PREV would lead to userid=8

and NEXT would lead to userid=10

 

 

when the user clicks next on 10

then PREV = 9

and NEXT = 11

 

 

Thanks for help.

Link to comment
https://forums.phpfreaks.com/topic/119858-grabbing-previous-and-future-ids/
Share on other sites

Well for all the i'ds you could grab all the data via mysql and store each individul row in a custom array:

 

$new_array = array();

 

Then you could check the current id:

 

$new_array[ $current_page_id ]

 

Then use the "prev()" function for previous and use the "next()" function for the next row in the table ;)

viewuser.php?userid=9

<?php
$detail = mysql_query("SELECT * FROM users WHERE userid='$userid'") or die(mysql_error());

while($user = mysql_fetch_array($detail)) {
	$userids[] = $user['userid'];
}


echo '<a href="viewuser.php?userid='.next($userids).'">NEXT ></a>';

?>

 

 

doesnt work....

Of course it's not working. Your are only selecting ID and then you made a link that is linking to that ID.

 

Not NEXT or PREVIOUS

 

You need to increase or decrease the ID for next or previous (or wathever you want to do)

 

So you could do:

 

$ID_higher = $user['userid']+1;
$ID_smaller = $user['userid']-1;
echo '<a href="viewuser.php?userid='.$ID_higher.'">NEXT ></a>';
echo '<a href="viewuser.php?userid='.$ID_smaller.'">PREVIOUS ></a>';

 

Now you need to get the correct ID... Work with it...

 

That can be your starting point. Although this isn't a very good way to do it, but it will get you going...

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.