Simple Machines Community Forum

SMF Support => SMF 2.0.x Support => Topic started by: cloksin on October 19, 2011, 06:43:35 AM

Title: changing the order in which posts are listed in a thread
Post by: cloksin on October 19, 2011, 06:43:35 AM
Not sure if this should go here or in the coding area.

I need to rearrange a couple of posts on my forum, I have a couple of threads that were merged but because of the order that the posts were made chronologically they are now out of order in reference to the story line they are portraying.  I went into the database and changed the time stamp on the posts, and the date on the posts changed, but their order didn't didn't.  I'm guessing the order is determined by the posts id in the messages database, is this correct?  Is their an easy way to change their order?  Is their a mod that will do this, or a simple SQL statement?
Title: Re: changing the order in which posts are listed in a thread
Post by: Oldiesmann on October 19, 2011, 11:24:26 AM
SMF does sort the posts based on their ID because in most cases, older posts will have lower IDs. The only way to change this is to physically change the IDs of the posts in the database, or, if you only want them sorted that way for a specific topic or two, change the code that pulls the details to sort them by date for those specific topics.
Title: Re: changing the order in which posts are listed in a thread
Post by: cloksin on October 19, 2011, 11:37:45 AM
What code would that be and where is it?
Title: Re: changing the order in which posts are listed in a thread
Post by: Oldiesmann on October 19, 2011, 12:02:32 PM
This is the query that handles it. It's located in Display.php:

$messages_request = $smcFunc['db_query']('', '
SELECT
id_msg, icon, subject, poster_time, poster_ip, id_member, modified_time, modified_name, body,
smileys_enabled, poster_name, poster_email, approved,
id_msg_modified < {int:new_from} AS is_read
FROM {db_prefix}messages
WHERE id_msg IN ({array_int:message_list})
ORDER BY id_msg' . (empty($options['view_newest_first']) ? '' : ' DESC'),
array(
'message_list' => $messages,
'new_from' => $topicinfo['new_from'],
)
);


Basically, you could do this:
if (in_array($topic, array('1', '2', '3'))
{
$messages_request = $smcFunc['db_query']('', '
SELECT
id_msg, icon, subject, poster_time, poster_ip, id_member, modified_time, modified_name, body,
smileys_enabled, poster_name, poster_email, approved,
id_msg_modified < {int:new_from} AS is_read
FROM {db_prefix}messages
WHERE id_msg IN ({array_int:message_list})
ORDER BY poster_time' . (empty($options['view_newest_first']) ? '' : ' DESC'),
array(
'message_list' => $messages,
'new_from' => $topicinfo['new_from'],
)
);
}
else
{
$messages_request = $smcFunc['db_query']('', '
SELECT
id_msg, icon, subject, poster_time, poster_ip, id_member, modified_time, modified_name, body,
smileys_enabled, poster_name, poster_email, approved,
id_msg_modified < {int:new_from} AS is_read
FROM {db_prefix}messages
WHERE id_msg IN ({array_int:message_list})
ORDER BY id_msg' . (empty($options['view_newest_first']) ? '' : ' DESC'),
array(
'message_list' => $messages,
'new_from' => $topicinfo['new_from'],
)
);
}


Just change those numbers in the array to the IDs of the topics that you want sorted by post time instead of ID.
Title: Re: changing the order in which posts are listed in a thread
Post by: cloksin on October 23, 2011, 10:41:38 AM
I couldn't get it to work, when I put that code in and refresh the topic specified in the array, I get nothing but a blank white page.
Title: Re: changing the order in which posts are listed in a thread
Post by: Aleksi "Lex" Kilpinen on November 21, 2011, 05:05:44 AM
Usually a blank white page is caused by an error in the code itself. Did it leave any errors in your server's error log?