Consistent Numbering

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
iknownothing
Forum Contributor
Posts: 337
Joined: Sun Dec 17, 2006 11:53 pm
Location: Sunshine Coast, Australia

Consistent Numbering

Post by iknownothing »

Hello all, I have a section on a site I am building which has visibly allocated numbers to each database entry. These numbers are editable to move an item up or down on a list.

The problem I am trying to solve is the ability to have consistent numbering, ie. 1,2,3,4,5,6... Currently, a user can enter any number in so it can end up jumbled, such as this 0,4,9,12,16,20,22....

Any ideas on how to do this?
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post by onion2k »

Code: Select all

$sql = "select id from table order by order_id";
$result = mysql_query($sql,$databaseConnection);
while ($record = mysql_fetch_object($result)) {
    $sql = "update table set order_id = ".++$o." where id = ".$record->id;
    mysql_query($sql,$databaseConnection);
}
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Users are allowed to specify the order number to create an entry under?
User avatar
iknownothing
Forum Contributor
Posts: 337
Joined: Sun Dec 17, 2006 11:53 pm
Location: Sunshine Coast, Australia

Post by iknownothing »

feyd wrote:Users are allowed to specify the order number to create an entry under?
its to do with the priority listings i was asking about around 3 weeks ago, it is separate to the ID of each field, after time it will all work out, but if for example someone accidentally enters in a 14, when they meant to enter 4, i would like it to jump back to the end of the consistent numbers ie. 1,2,3,4.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Ah, the field name wouldn't seem to correlate to its use.
Post Reply