News:

Bored?  Looking to kill some time?  Want to chat with other SMF users?  Join us in IRC chat or Discord

Main Menu

changing the order in which posts are listed in a thread

Started by cloksin, October 19, 2011, 06:43:35 AM

Previous topic - Next topic

cloksin

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?
SMF 2.0.1
SimplePortal 2.3.3

Oldiesmann

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.
Michael Eshom
Christian Metal Fans

cloksin

SMF 2.0.1
SimplePortal 2.3.3

Oldiesmann

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.
Michael Eshom
Christian Metal Fans

cloksin

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.
SMF 2.0.1
SimplePortal 2.3.3

Aleksi "Lex" Kilpinen

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?
Slava
Ukraini!
"Before you allow people access to your forum, especially in an administrative position, you must be aware that that person can seriously damage your forum. Therefore, you should only allow people that you trust, implicitly, to have such access." -Douglas

How you can help SMF

Advertisement: