How to show newest thread in subforum

Associate
Joined
6 Nov 2006
Posts
722
Location
Devon
I'm wondering what the easiest way to get a page to display the newest thread in a subforum. I'm wanting to know as I want to make an app where one of the buttons will go to the newest thread in a subforum to save having to navigate to it on a mobile device which usually takes ages over a mobile connection. Can anyone tell me how to achieve this?
 
Which subforum? Your forum? If you have access to the database you could just do an SQL query to find the thread with the most recent date and create a link to it somehow.

If you're talking about a forum you browse and your app has no access to said forum internals then most likely you'd have to have your app crawl the webpage and find the dates of threads and find the recent one and then generate a link to it.
 
Thanks for the reply, it is a forum on a site I administer which runs on wordpress if this makes a difference. I have no idea about running an SQL query to find the right thread, I have only done a very little SQL ages ago and can't really remember any of it so if I could get any help with it or could be pointed in the right direction I'd be very grateful
 
Well without seeing how the forum table is structured I wouldn't know the exact query but I suppose the query would be something like this

SELECT thread_id FROM thread_table WHERE forum_id=5 ORDER BY thread_date DESC LIMIT 1

So like for example this thread (this OcUK one) has an id of 22464906 and with that you can construct an url to point to it.

The variable names should be replaced with what is relevant according to your table.

All the above code is doing is selecting the id of the thread from your thread table where the forum id is the subforum where the threads you want to check for are, and it's ordered by the thread date descending so the first one will be the newest thread. Since you only need the first limit the query to 1 result.

If the SQL passes over your head then have a quick read on http://www.tizag.com/sqlTutorial/

Only other way would be for your app to read the html of the page and do a similar thing, but it won't have all the data in an organized format like the database and you'd have to program it to find all that info.
 
Back
Top Bottom