1. ORDER BY Algorithm

Hello

I am working on a php/mysql driven website where users can make posts.
Other users can vote up/down on these posts.

I am working on an Algorithm to order these posts.
I want the posts with the highest NET points to be displayed on top, however I also want to give priority to new posts.

This is what I have so far,

Code:
`ORDER BY points_up - points_down DESC, timestamp DESC`
However I want to do something along these lines.

Code:
`(points_up - points_down) / minutes`
The minutes being the number of minutes the post has been active. However I'm not sure how to implement the minutes feature using my timestamp.

2. "the number of minutes the post has been active"

where is this information coming from?

3. I am using the timestamp along with a php script to display how many minutes old a post is.

PHP Code:
``` \$todaydate = date("Y-m-d H:i:s");\$ago = strtotime(\$todaydate) - strtotime(\$row['timestamp']);if (\$ago >= 86400) {\$diff = floor(\$ago/86400).' Days ago';} elseif (\$ago >= 3600) {\$diff = floor(\$ago/3600).' Hours ago';} elseif (\$ago >= 60) {\$diff = floor(\$ago/60).' Minutes ago';} else {\$diff = \$ago.' Seconds ago';}\$diff2 = floor(\$ago/60).' Minutes ago';  ```

4. i'm sorry, i don't do php

5. Well currently all I have is the timestamp that contains the time and date the post was submitted.

I want to know how I can divide the NET total by the timestamp.

6. Originally Posted by Jaynesh
I want to know how I can divide the NET total by the timestamp.
i thought you actually wanted to divide by minutes since the post has been active

what is the DATATYPE of the timestamp column?

7. Hi

The datatype is 'timestamp'

8. Code:
```ORDER
BY (points_up - points_down) /
( ( UNIX_TIMESTAMP() - UNIX_TIMESTAMP(timestamp) / 60 )```

9. Are you missing a closing parenthesis? I count two opening and one closing on the timestamps...

Originally Posted by r937
Code:
```ORDER
BY (points_up - points_down) /
( ( UNIX_TIMESTAMP() - UNIX_TIMESTAMP(timestamp) / 60 )```
Should it be....
Code:
```ORDER
BY (points_up - points_down) /
( ( UNIX_TIMESTAMP() - UNIX_TIMESTAMP(timestamp)) / 60 )```
???

10. nicely spotted, thanx

Posting Permissions

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