Next Thread button (General)

by Andy, Thursday, April 26, 2012, 09:40 (4421 days ago)

Hi

I am trying to create a 'next thread' button. In 'Table' view this will sit at the bottom of all the posts, and in 'Thread' view it sits in each post.

I have successfully edited 'entry.inc.tpl', 'thread.inc.tpl' and 'thread_linear.inc.tpl to include this button but am really having trouble getting it to link to the first post in the next thread.

I have tried:

<a href="index.php?id={$tid-1}" title="Next Thread">NEXT THREAD</a>

But I realise this is not 100% correct, and that I may need a new function set up in the entry.inc.php file.

I've spent a fair few hours trying to solve it and now admit I'm stuck. Any guidance would be much appreciated!

Thanks in advance.

Avatar

Next Thread button

by Auge ⌂, Friday, April 27, 2012, 10:14 (4420 days ago) @ Andy

Hello

I am trying to create a 'next thread' button. In 'Table' view this will sit at the bottom of all the posts, and in 'Thread' view it sits in each post.

I have tried:

<a href="index.php?id={$tid-1}" title="Next Thread">NEXT THREAD</a>

But I realise this is not 100% correct, and that I may need a new function set up in the entry.inc.php file.

I've spent a fair few hours trying to solve it and now admit I'm stuck. Any guidance would be much appreciated!

The thread-ID (field 'tid' in the database, variable $tid for PHP) is equal to the ID of the opening posting of a thread. Your construction id={$tid-1} only fits, if there are only opening postings. If only one answer posting is present, wich was posted inbetween two opening postings [1], it will fail.

You need a list of the ID's of opening postings, respectively ID's of the threads. You can ask the database with an additional query. On the other side the mentioned list is part of the result for the database query on the main page (wich lists all threads for this page). Either you extract the opening postings to an array in the script wich generates the main page and saves it i.e. as a session variable for use on further pages or you generate this list on every page [2]. In both cases you have to order the list either by date of opening posting or the last answer to the mentioned threads.

The generation of the list at every single page request has a additional advantage. You only need the ID's of the last and the next thread. The result of this query is smaller than the whole list. Besides the list from the main page is incomplete because it lists only the ID's for the view of a given number of threads (i.e. 25). You'll get no ID for the last thread if you open a posting of the last thread wich is present on the main page.

[1] ID opening posting #1: 1; ID answer to opening posting #1: 2, ID opening posting #2: 3
[2] If you extract the IDs of opening postings from the main-page-database-result you have to do it only once, but it may be outdated, if the posting frequence is very high. A query for every page view/request is actual by definition, but it generates additional server load.

--
Trenne niemals Müll, denn er hat nur eine Silbe!

Next Thread button

by Andy, Monday, April 30, 2012, 09:18 (4417 days ago) @ Auge

Thanks very much Auge, for your detailed reply. That is exactly what I needed to get me in the right direction. Watch this space....!

RSS Feed of thread