Hello all of you .

I just wana know to return to same id when we delete it from the database

for exmaple when we delete the user_id that equal to 1 the next when we

enter the new record the user_id will became 2 i want to make it one in the

databse record . thats all and thanks in advance ....

Why do you want to do this?


anyway, if you really, really want to do this, you can do it on insert. when you want to save a new record, first you get the last ID, and when insert the new record, you increment it by 1. also, be sure your column has no auto_increment property.

I agree with silviuks that generally, what you want isn't a good idea :-)

I'm not sure if what you are after is to fill blanks in a row of user_ids.
What if you have three users: 1, 2, 3 and delete 2. Do you want the next new user to receive 2 again or 4?
If your answer is 2 then I suggest you forget about it. This really stinks (http://en.wikipedia.org/wiki/Code_smell). Perhaps tell us why on Earth you would want something like this and we help you solve the real problem.

just set your id auto_increment..

thanks all for your help

he has ids 1 2 3 4
he deletes 2 so now he has 1 3 4
he wants to loop through the ids so that they would become 1 2 3, which I am not sure if this a good or bad idea as would it mess everything up.

I would say it is a hiddeous idea honestly. This because what if there are references to the user_id in other tables? Then you would have to go through all these tables and update them to match the new settings. This can cause a lot of needless overhead for your application and your users won't want to sit there waiting for the updates to happen.

I would suggest setting your user_id column to a large enough integer for what you need and then do as forzadraco said and set the column to auto_increment.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.