How to enter a sort position into a database

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
weysider
Forum Newbie
Posts: 2
Joined: Mon Aug 15, 2011 5:22 am

How to enter a sort position into a database

Post 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?
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: How to enter a sort position into a database

Post 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.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
weysider
Forum Newbie
Posts: 2
Joined: Mon Aug 15, 2011 5:22 am

Re: How to enter a sort position into a database

Post 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?
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: How to enter a sort position into a database

Post 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?
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Post Reply