Jump to content

[SOLVED] Update all entries' id


Ken2k7

Recommended Posts

For example, I have the following table:

 

Table name: GniM

Columns: id AUTO_INCREMENT, n1, exf, urls

PRIMARY_KEY(id)

 

I only put up the important stuff. So id will auto increment all the time. But since I have a system to remove entries, the entries don't get updated. What I meant by updated is: when I delete a row, I want all the entries in the database to reset their ID. So if I have 5 entries and I delete the 4th entry, then the fifth entry will be the 4th. So it's just an ID change. How would I do that? Also, I will need to reset AUTO_INCREMENT to the next available number. How would I do that?

 

I can always just reset AUTO_INCREMENT to the next available number so that the next entry will be in the 4th position instead of the 6th. But that means I would need to keep skipping with AUTO_INCREMENT. That's too hard.

 

Thanks in advance,

Ken

Link to comment
Share on other sites

If space isn't an issue, add another column?  a column called deleted.  Then in your query, select whatever WHERE DELETED='No'.  The the 'deleted' ones, change it to yes?  Or does that not satisfy what you're trying to do?

 

We need more information in order to tell you what the best choice would be...

Link to comment
Share on other sites

If space isn't an issue, add another column?  a column called deleted.  Then in your query, select whatever WHERE DELETED='No'.  The the 'deleted' ones, change it to yes?  Or does that not satisfy what you're trying to do?

 

We need more information in order to tell you what the best choice would be...

Interesting ideas. What would the column_name description be for boolean values?

Link to comment
Share on other sites

Hi Ken,

 

I re-read my post and I wanted to say I did not mean to sound like an ass.....

 

This seems like a lot of work and extra coding. Is there a particular reason you want to do this? Although I don't see the purpose, you may have a very valid reason, so I am curious as to why.

 

Seeing why others do certain things helps me broaden my knowledge and may very well help me in a situation.

 

So again, sorry to sound like a jerk :)

Link to comment
Share on other sites

Hi Ken,

 

I re-read my post and I wanted to say I did not mean to sound like an ass.....

 

This seems like a lot of work and extra coding. Is there a particular reason you want to do this? Although I don't see the purpose, you may have a very valid reason, so I am curious as to why.

 

Seeing why others do certain things helps me broaden my knowledge and may very well help me in a situation.

 

So again, sorry to sound like a jerk :)

chronister, you may not remember me, but I do remember you around here. You are one of the more helpful people around here. I know that and I do appreciate all the help you've given others.

 

The reason I did not respond to your inquiry was because this matter was for my work and I'm not allowed to leak any information I'm not allowed to. I want to reset the ID so that when I list the data onto the page, I can just use the ID as index numbers rather than manually using a $count variable and continually increment it for listing purposes.

 

I think xtopolis made an easy way for me to do this. I'll use his method and just use 0 and 1 for on and off.

 

Thanks all though. ^_^

Link to comment
Share on other sites

Ken,

 

chronister, you may not remember me, but I do remember you around here. You are one of the more helpful people around here. I know that and I do appreciate all the help you've given others.

 

Thank you for your kind words, I really appreciate that. I don't "remember you" in the sense of a particular topic or post, but I do know that I see your name all over the place around here and have for quite some time.

 

No worries on not responding to me, I had just re-read my post and thought it came off as a little "rude" sounding. Funny how tone and "mood" can be picked up in text only... :)

 

Your reasoning makes sense to me, and I understand the whole hush hush work project thing. Good luck with this.

 

Nate

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.