Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3

Thread: Ordering a list

  1. #1
    Regular Coder
    Join Date
    Mar 2007
    Posts
    357
    Thanks
    46
    Thanked 22 Times in 21 Posts

    Unhappy Ordering a list

    Ok, it's actually in PHP. But the answer I need is just basic maths. I feel stupid but I can't figure out how to do it properly. I'm writing a forum and it works a charm at the moment. Only problem is order.

    When a person submits the post, it sends the topic ID to the target page and then moves that topic to number 1 in the order list. So far example:

    1st Topic | Order: 1
    2nd Topic | Order: 2
    3rd Topic | Order: 3
    4th Topic | Order: 4

    User posts in topic 4 so now it's:

    1st Topic | Order: 2
    2nd Topic | Order: 3
    3rd Topic | Order: 4
    4th Topic | Order: 1

    Thats easy enough, I just +1 to all of them after making the chosen topic number 1. But if they choose topic 3 then this happens:

    1st Topic | Order: 2
    2nd Topic | Order: 3
    3rd Topic | Order: 1
    4th Topic | Order 5

    The Order number can't be higher than the max ammount of topics, which is 4 in this example.

    Theres probably a damn simple way of doing this that i'm just not seeing, and I feel really stupid because I don't usually have a problem with the maths side of things. What could I do to sort out this order problem?

  • #2
    Banned
    Join Date
    Feb 2008
    Location
    Winnipeg, Canada
    Posts
    396
    Thanks
    0
    Thanked 29 Times in 29 Posts
    You're making a mountain out of a molehill. Instead of doing it with some kind of order thing, add a timestamp column (let's call it `tstamp`) and just update it with the current timestamp every time you add a post to it. Finally, when you go to list the topics use a query such as:

    PHP Code:
    SELECT FROM topics ORDER BY tstamp 

  • #3
    Regular Coder
    Join Date
    Mar 2007
    Posts
    357
    Thanks
    46
    Thanked 22 Times in 21 Posts
    Oh wow, I didn't think about it that way. Damnit! Thanks a million . Data table was already there for 'Last Post' so that takes care of 2 problems with one thing.

    Tyty


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •