How to sort items by rank, and how to add variables.

Ok, so first off, I know next to nothing about PHP. Im figuring it out bit by bit, but Im still a total noob.

What I need to do is basically this:

[ul][li]I will have a number of items that need to be listed on a webpage[/li]
[li]Each item will have a score, based on how many votes its recieved.[/li]
[li]I need to have the list of items sorted by score.[/li][/ul]

I already know how Ill retrieve the data for the score, and how to use forms to submit a vote and such. What I need to figure out is
A) How to sort the items in a list by their score
B) how to add each vote to the total

For the adding, I imaging it would be something like thios psuedo code:

var Current_score = (score retrieved from database)
if vote recieved
     current_score = current_score +1

(send new score back to database)

Can anyone help me out with this?

Can you post up your code and it will allow us to help more and to integrate everything.

Well I really dont have anything final written out yet. Ive been looking at tutorials, and so Ive figured out how to use mysql_query to read and write from my database, and so Im just going to have a single table on the database, that will store the item’s name, and the number of votes it has.
Then each time a vote is cast, Ill read the number of votes from the database, add 1 to it, and re-write it back to the database.
Im thinking Ill use either tables or div tags to actually display everything, but I dont know how easy either would be to make sortable by votes.

Just in your MySQL statement you just put ORDER BY score DESC that will return the array in descending order.

Sponsor our Newsletter | Privacy Policy | Terms of Service