Jump to content

delete number modify order


dragon_sa

Recommended Posts

if its an autonumber column then it should do it automatically anyway...

 

Perhaps you could do a SELECT max statement to see what the biggest number is, then INSERT +1 that

 

$result = mysql_query("SELECT max(numbercolumn) FROM table",$link);

$newnumber = mysql_result($result,0,0) + 1;

Link to comment
Share on other sites

The column is not an auto number, its a display order

it gets created with max +1 everytime a new item is added to the table, if I delete any of the ordered numbers I would like to -1 from every item number above that number deleted to bring the sequence back into line and not skip any numbers.

Link to comment
Share on other sites

I like that thorpe can I throw 1 little spanner into that

 

The fields in the columns are also part of categories which are numbered eg

 

Order  Category

1        1

2        1

3        1

4        1

5        1

6        1

7        1

1        2

2        2

3        2

1        3

2        3

3        3

4        3

 

Can I use that with GROUP so only the numbers that are part of that GROUP are affected or would i be better with some sort of for each statement?

 

I believe that is the only spanner :)

Link to comment
Share on other sites

If it's being done on the fly though, can't you just do that as you go along and make sure you're editing the right category?

 

UPDATE tbl SET fld = fld-1 WHERE fld > 4 AND category = 1

 

It sounds like this is what you want :)

 

User: deletes item at 4th order in category 5, update category 5

User: deletes item at 2nd order in category 3, update category 3

Link to comment
Share on other sites

thank you very much for your help this is what worked a treat fro me

 

// update order of catalogs
$ordsql="UPDATE catalog SET catOrder=(catOrder-1) WHERE catOrder > '$catNum' AND collectionID='$catCollID'";
$resultorder = mysql_query($ordsql);

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.