» Quick Links
You can make money on these forums
We Share profits with you
Google
Google Adsense
Google Adwords
YPN
Yahoo
MSN Search
Web Directories
Web Hosting
Web Hosting Offers
Hosting News
Suggestions
Link Building
Domain Names
PHP Forums
MySQL Forums
» More Links
OSP News
Reseller Hosting
Shared Hosting
Dedicated Servers
Google Adsense
Search Engine Marketing
Link Development
Affiliate Marketing


» Advertising
Multiple DC PR Check

Free SEO Tools


Go Back   Webmaster Forums > Website Developement / Programming > PHP Programming and Tips

PHP Programming and Tips Discuss about PHP programming and Share Tips. Ask questions about Scripting and Errors.

Reply
 
Thread Tools Display Modes
  #1  
Old 08-19-2006, 10:53 AM
lucky7 lucky7 is offline
Junior Member
 
Join Date: Aug 2006
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
lucky7 is on a distinguished road
Default next and previous record from table

Hello,

I have a table with data like this.....


Code:
ID Name
--- ------
3 James
1 Bill
6 Tom
5 Andy
2 John
4 Fred


What im tryin to do is figure a way to return the current record, along with the next and previous record IDs. For instance, if I were sitting on record with ID 6 then I want to grab also the next and previous IDs. Thing is, although the IDs are unique - they aren't sequential and there may be gaps.

Can anyone help with the best way of approaching this? It's basically for a gallery script. You preview thumbnails and when you click one it shows the full picture. While that picture is displayed, i'm after showing links to jump to the next or previous pictures without going back to the thumbnail page.

Thanks a lot -- This message may have been cut off and the rest will only be shown to members. To become a member, click here --
Reply With Quote
Revenue Sharing Ads ( ?):
  #2  
Old 08-19-2006, 10:55 AM
hannah hannah is offline
OSP Addicts
 
Join Date: Apr 2006
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
hannah is on a distinguished road
Default

Hi mate
Add another column to the table, make it auto_increment and then use that to determine the previous/next image.
Good day -- This message may have been cut off and the rest will only be shown to members. To become a member, click here --
Reply With Quote
  #3  
Old 08-19-2006, 10:57 AM
matthew matthew is offline
OSP Starters
 
Join Date: Apr 2006
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
matthew is on a distinguished road
Default

You have to have primary key in your table and then you can do something like

PHP Code:
while ($row = mysql_fetch_row($result))
{
$thisId = $row["Id"];
}

$lastId = $thisId - 1;
$nextId = $thisId + 1;

and if you want to select complete records of next and prev ids then write queries based on last and next ids vars,

PHP Code:
select * from tb where id=$lasdId
select * from tb where id=$nextId -- This message may have been cut off and the rest will only be shown to members. To become a member, click here --
Reply With Quote
  #4  
Old 08-19-2006, 11:22 AM
acerman acerman is offline
OSP Addicts
 
Join Date: Jun 2006
Posts: 36
Thanks: 0
Thanked 2 Times in 1 Post
Rep Power: 18
acerman is on a distinguished road
Default

If you have IIS installed locally you should be able to type
http://localhost/..... to connect. -- This message may have been cut off and the rest will only be shown to members. To become a member, click here --
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT. The time now is 08:42 AM.