Jump to content

grabbing previous and future id's


MikeDXUNL

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...

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.