show previuos record or next record

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
bhanu
Forum Commoner
Posts: 46
Joined: Thu Nov 05, 2009 4:25 am

show previuos record or next record

Post 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
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: show previuos record or next record

Post 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.
bhanu
Forum Commoner
Posts: 46
Joined: Thu Nov 05, 2009 4:25 am

Re: show previuos record or next record

Post 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
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: show previuos record or next record

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