MikeDXUNL Posted August 15, 2008 Share Posted August 15, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/119858-grabbing-previous-and-future-ids/ Share on other sites More sharing options...
lonewolf217 Posted August 15, 2008 Share Posted August 15, 2008 if you are showing one ID per page, just have your NEXT link point to <yourpage>.php?id=x where x is the current ID +1 Quote Link to comment https://forums.phpfreaks.com/topic/119858-grabbing-previous-and-future-ids/#findComment-617478 Share on other sites More sharing options...
Demonic Posted August 15, 2008 Share Posted August 15, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/119858-grabbing-previous-and-future-ids/#findComment-617484 Share on other sites More sharing options...
MikeDXUNL Posted August 15, 2008 Author Share Posted August 15, 2008 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.... Quote Link to comment https://forums.phpfreaks.com/topic/119858-grabbing-previous-and-future-ids/#findComment-617495 Share on other sites More sharing options...
budimir Posted August 15, 2008 Share Posted August 15, 2008 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... Quote Link to comment https://forums.phpfreaks.com/topic/119858-grabbing-previous-and-future-ids/#findComment-617526 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.