Skip to content
Advertisement

SQL Query merging with PHP assistance please

I want to sort the messages by poster_time instead of the usual id incrementing as I have restored a database with auto incrementing id’s and very old messages show up on top I had like to be able to sort them by poster_time to fix that problem.

I’ve attempted to fix this myself but I don’t want to lose any functionality, here is my attempt.

to this for testing purposes

Using the code above I’ve figured out I need ml.poster_time DESC how do I bundle it up with the code at the very top.

Here the structures

boards structure alt text alt text alt text

Thanks – I have been suffering with this for a whole week now.

Advertisement

Answer

It looks like you’re wanting topics to be sorted in this order: 1) sticky, 2) sort from query string or if empty, 3) post date.

Before you assemble your query variable, add this line:

Basically this is saying that if another sort method hasn’t already been chosen (i.e. alphabetical), then default to sorting by the date posted.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement