Jump to content

[SOLVED] how do i re-number my rows in my db


Lodius2000

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.