Jump to content

Archived

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

davinci

AUTO INCREMENT question...

Recommended Posts

Hi,

Have a video post site and I use mySQL to display my videos through out my site. Whenever I upload a video it has an 'id' which is auto incremented. Each video is displayed with the following URL structure:

../video.php?id=1, ../video.php?id=2 and so on.

I've deleted a whole bunch of videos and kept the few good ones. I renamed all my last 5 remaining 'id' entries so that they would be 1, 2, 3, 4, 5 instead of a bunch of gaps between numbers for the ones I've deleted. But now when I add an entry its being added as id 12 instead of 6 (as if I didn't delete entries). Is there a way around this? I just don't like having the gap in my site structure.


In PHPmyAdmin I can see "Next Autoindex 12", is there a way to chaneg this value?

Thanks!

[!--quoteo(post=350113:date=Feb 27 2006, 09:25 PM:name=davinci)--][div class=\'quotetop\']QUOTE(davinci @ Feb 27 2006, 09:25 PM) [snapback]350113[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Hi,

Have a video post site and I use mySQL to display my videos through out my site. Whenever I upload a video it has an 'id' which is auto incremented. Each video is displayed with the following URL structure:

../video.php?id=1, ../video.php?id=2 and so on.

I've deleted a whole bunch of videos and kept the few good ones. I renamed all my last 5 remaining 'id' entries so that they would be 1, 2, 3, 4, 5 instead of a bunch of gaps between numbers for the ones I've deleted. But now when I add an entry its being added as id 12 instead of 6 (as if I didn't delete entries). Is there a way around this? I just don't like having the gap in my site structure.
In PHPmyAdmin I can see "Next Autoindex 12", is there a way to chaneg this value?

Thanks!
[/quote]

Found a feature in PHPmyAdmin table options to set the current auto increment value however when I enter a new one when it runs the query it doesn't actually change it sets the value for the original one (12).

Share this post


Link to post
Share on other sites
Why is everyone so hung up on these silly IDs? Who cares what the number is... (sigh)

Anyway, you need to run a "ALTER TABLE AUTO_INCREMENT = 1" -- that will reset the counter. But as I've said many times before, it's unnecessary and unwise to rely on this number for anything at all except referential integrity.

Share this post


Link to post
Share on other sites
Fenway's right, just leave the data be. Start doing that when you have a real database, and you'll get in trouble fast.

Share this post


Link to post
Share on other sites
[!--quoteo(post=350138:date=Feb 27 2006, 11:34 PM:name=wickning1)--][div class=\'quotetop\']QUOTE(wickning1 @ Feb 27 2006, 11:34 PM) [snapback]350138[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Fenway's right, just leave the data be. Start doing that when you have a real database, and you'll get in trouble fast.
[/quote]

hey i have like the exact same problem! but you would reccomend somethign else instead of auto-increment ids? i have a relational database and with each tables id's is how i relate them to each other, therefore deeming it very important, you say that this isn't good?

i'm curious to what practice or strategy you would advise then instead of this? all the php books i've read uphold these id numbers..lol

Share this post


Link to post
Share on other sites
No, auto increment is great, fabulous, fundamental, can't live without it. Just don't fiddle with the id once it's been assigned. Don't try to fix gaps or make the numbers "pretty".

Share this post


Link to post
Share on other sites
Exactly -- if you want to have pretty numbering on your page, do it in the output as your iterate over your result set; don't worry about the how the database internally handles it.

Share this post


Link to post
Share on other sites

×

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.