Jump to content

Recommended Posts

I have a table with an INT field called id, i have a script that can delete a row if needed, problem is i need to re-number all of my rows because if i delete id=3, i am left with 1,2,4,5...

 

I think i could do it with a few array functions (but im coming up blank on which they are), also the only way i can think to do that would be to set up a foreach and do an update for all the rows

 

but could it also be done in sql

 

help

thanks

I have a table with an INT field called id, i have a script that can delete a row if needed, problem is i need to re-number all of my rows because if i delete id=3, i am left with 1,2,4,5...

 

And the problem with that is?

It doesn't matter if you have a gap in the numbers as they are just used as unique identifiers.

hrm, i guess other than for display purposes (i use the old '<tr class="' . $styles[$i % 2] .'">' trick to make the table easier to read) it doesnt

 

Primary keys should not be relied upon for ordering or manipulating the way data is displayed for this exact reason.

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.