Page 1 of 1
Consistent Numbering
Posted: Sun Jan 07, 2007 11:46 pm
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?
Posted: Mon Jan 08, 2007 2:28 am
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);
}
Posted: Mon Jan 08, 2007 9:06 am
by feyd
Users are allowed to specify the order number to create an entry under?
Posted: Mon Jan 08, 2007 5:47 pm
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.
Posted: Mon Jan 08, 2007 5:55 pm
by feyd
Ah, the field name wouldn't seem to correlate to its use.