Alright, so I've looked EVERYWHERE about how to sort/order hierarchical data with some sort of arbitrary value, like alphabetically, highest votes, etc. Do any of you have any solutions for a nested set or something else?
Here's a couple example queries that a guy made on reddit in my thread and I added to (unioning a lot of selects.. help?):
http://sqlfiddle.com/#!9/6dd457/10 - alphabetically and still in order http://sqlfiddle.com/#!9/786d89/36 - in order of highest votes first
These are adjacency lists at heart, and the mysql creates a materialized path based on your sorting parameter on the fly. This would be generated every time someone goes to viewtopic.php as each user has their own custom sort.
Now there are a few issues with this approach. First, seeing all of those selects and joins makes me a bit worried. I assume there's a much more optimized way to make all of this.
Php can be used to work out the highest parent node value, how many layers down we want to generate from that, and the formatting of some other things, but there's the problem with this crap in there too:
(1000 - l1.TotalVotes)+(2 * l1.Negatives) - having to be repeated like 5 times in the whole query
I tried to do ((1000 - l1.TotalVotes)+(2 * l1.Negatives)) AS l1.Votes in its respected select query, but I got an error :/ that would be one step to making it cleaner.
My ultimate goal is making a query that is able to sort in the order that I want, so I can just use templating with depth information to generate the html without having to use php any more than I have to, seeing as how sql is more efficient and meant for these sorts of things. I'm mostly worried that a query looking like that will be bad for larger sites.
The end goal is to have something as fast as reddit: nested comments with the ability to sort by post date, vote total, and some other parameters, all using as much mysql and as little php as possible. If you have any solutions to this using closure tables, nested sets, or just plain materialized paths, I'd love to hear them. The solution I have here looks optimized and scary.