Page 1 of 1

How to enter a sort position into a database

Posted: Mon Aug 15, 2011 5:30 am
by weysider
I would like to do the following:

Sort a database table based on the value of one of the items in the table (no problem), then update another item in the table with the position of the row in the sort.

So, say, it was a football league table:
Sort by Points DESC, Goal Diff DESC to come up with a league table order, then write back into the database (say to a variable called POSITION) the position of the club in that table.

I have looked, but I have not found how to do this.

Can someone help please?

Re: How to enter a sort position into a database

Posted: Mon Aug 15, 2011 8:00 am
by AbraCadaver
You shouldn't store values that are calculated in your database. Position is based on points and goal diff, so just calculate and display the position when you need to.

Re: How to enter a sort position into a database

Posted: Mon Aug 15, 2011 10:20 am
by weysider
Hmmm, but I do want to do this.

For example, I might use the value to retrieve it and show "position last month".

Really, is there no way?

Re: How to enter a sort position into a database

Posted: Mon Aug 15, 2011 11:10 am
by AbraCadaver
There is a way, but it's not really the correct way so far as I know. Get the points and goal diff for the previous month and calculate the position.

Suppose last month there was an error when entering the points for one team. When you go back and edited it, then you have to recalculate and store the positions again. Also, in this scenario it's not likely, but what if there is a change to the algorithm that determines the position?