Page 1 of 1

show previuos record or next record

Posted: Tue Dec 08, 2009 12:44 am
by bhanu
hi all
In my i have displayed users profiles.
when click on view profile link the page is redirect to view_profile.php?uid=10004
now i want to display pagination at view_profile.php?uid=10004 page like <prev next>
when we click on <prev link it will redirect to view_profile.php?uid=10003 .for next> link it wwill redirect to view_profile.php?uid=10005 .

in my database i have a tabel for users . records are like shown below.
----------------------------------------------------------------------
id | name | email | picture | password | phone | address | dob
-----------------------------------------------------------------------
1001 a sdf 1.jpg hfg 657 556

1002 b dummy ghf dummy dummy dummy dummy

1003 c dummy dummy dummy dummy dummy dummy

1004 d dummy dummy dummy dummy dummy dummy

1005 e rr rtt rtt 456 45656 4656

-------------------------------------------------------------------------

thank you in advance

please help me

regards
bhanu

Re: show previuos record or next record

Posted: Tue Dec 08, 2009 12:56 am
by requinix

Code: Select all

SELECT `id` FROM `table` WHERE `id` < 10004 ORDER BY `id` DESC LIMIT 1
SELECT `id` FROM `table` WHERE `id` > 10004 ORDER BY `id`ASC LIMIT 1
That'll give you the previous and next IDs.

Re: show previuos record or next record

Posted: Tue Dec 08, 2009 4:58 am
by bhanu
thank you for fast reply.

in this forums at top of links we have seen topright corner two links are there. right?
<<previous topic | Next topic>>

like wise i want to display users profiles ...........

help me
regards
bhanu

Re: show previuos record or next record

Posted: Tue Dec 08, 2009 5:07 am
by jackpf
[sql](SELECT MAX(`id`) AS `previous_user_id` FROM `users_table` WHERE `id` < $current_user_id LIMIT 1)UNION(SELECT MIN(`id`) AS `next_user_id` FROM `users_table` WHERE `id` > $current_user_id LIMIT 1)[/sql]
Is how I'd do it...

Something like that anyway.