tags:

views:

61

answers:

1

Hi

I'm making a forum for skills.

I want to print a previous and/or next link on the thread page. So if theres a thread with a larger and/or lesser number than current, print it in lionk. And also i wanna limited only threads from the same forum as the thread im viewing is located in.

Basically likes this forum:

http://forum.tibia.com/forum/?action=thread&threadid=3099663

Look under the Post Reply button.

Thanks alot

A: 
SELECT MAX(id) as prev_thread_id
  FROM threads
 WHERE id < <current_thread_id>
   AND forumid = <current_forum_id>

and

SELECT MIN(id) as next_thread_id
  FROM threads
 WHERE id > <current_thread_id>
   AND forumid = <current_forum_id>
Mark Baker
Thanks. Now I just have to figure out the php part.
Tomek Wojtek
@Tomek be careful this can work, but it can be sonfusing auto increment ID are not a timeline and id of deleted records can be reassigned by MySQL. If you can, I suggest you to use date fields instead of ID.
Benoit
@Benoit "id of deleted records can be reassigned by MySQL" Can you cite a reference on this? I'm very concerned if it is the case.
Mark Baker
Sure, I did the painful experienced of this behavior. See comments on http://dev.mysql.com/doc/refman/5.1/en/example-auto-increment.htmlIt seems this is a bug, but I can't get sure of this.For me, with mysql 4.1 it was using very large set of data on MyISAM with daily massive delete/inserts, and deleted ID were reassigned by the time
Benoit