Jul 25, 2008

Delete Problem With Id - Id as auto_increment, and identifier for a row

Free Web Hosting, No Ads > CONTRIBUTE > Computers > Programming Languages > PHP Programming

free web hosting

Delete Problem With Id - Id as auto_increment, and identifier for a row

serialmike
Whenever I use 'delete from table where id = 4' from a table with several rows up to 10, the 4th row is removed and the update simply shows the rest from 1 to 10 without 4. This is not what I want. I want the table to now read 1 through 4 to 9 so that futher delete actions will be in that sequence. I want to identify my row with the id (number). Can anybody help out here. Very urgent.
Serialmike.

Reply

shadowx
The reason this happens is because you havent told the database to update the ID fields, you've only told it to remove the fourth row and do nothing else. I cant think of an efficient and simple way to solve this, there could be a built in function for it but i dont know of one. The only solution i can think of is to manually update each ID field that comes after the deleted row with a "-1" instruction that should result in each ID being in sequence and you'd have to use a loop to do this for each field which could be very long.

Reply

serialmike
QUOTE(shadowx @ Dec 11 2007, 03:38 PM) *
The reason this happens is because you havent told the database to update the ID fields, you've only told it to remove the fourth row and do nothing else. I cant think of an efficient and simple way to solve this, there could be a built in function for it but i dont know of one. The only solution i can think of is to manually update each ID field that comes after the deleted row with a "-1" instruction that should result in each ID being in sequence and you'd have to use a loop to do this for each field which could be very long.


Shadowx,
You are very rigth in theory. I have thought along your idea, but it sounds complicated hence my coming to this board if there is a shorter approach to the problem. I still hope there is an inbuilt command or sql statement for this. It appears to be a common problem, and as such, would have attracted attension. Will you be kind enough to translate your idea into code (php)? Is foreach() a useful function for this?
Regards, serialmike

 

 

 


Reply

galexcd
There is only one fix that I can think of that doesn't require manually relabeling every row, but it is sloppy and I do not recommend it. If you have your sql query delete the ID column and remake it with auto_increment it will relabel every row properly. But like I said it is very sloppy and I do not recommend it because if you have many rows and you you delete a column that other pages may need and remake it it may cause some errors if somebody else is loading another page at exactly the right time.

Reply

jlhaslip
serialmike,

In order to answer this question more intelligently, we would need to see your database structure. Since the "id" is presumably the Primary Key for the Data Table you want 'sequentially' numbered, what other data sets are affected? Assuming this is a 'members' table, is this a Foreign key for other tables? Are members assigned to groups using this key? Is this key used to track their attendance at a forum? Or their posting activity?
The Database structure will let us see if their are complications to deleting and re-organising the Data.
If you simply need a 'count' of the members, can you use the count function?
One of the greatest advantages to using a database for recording information is the ability to use this 'key' to track data rows. The 'ID' number does not need to be sequential. You risk major contamination of the Database by affecting the 'id' of a dataset. Forewarning is given.

Reply



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.
Confirm Code:

Similar Topics

Keywords : delete, problem, id, id, auto, increment, identifier, row

  1. Postage Costs Problem For My Website
    Ideas for postage system needed (3)
  2. Need Help: Problem Seeing My Site
    maybe i screwed up? (3)
    I just got my account activated yesterday. so i logged in thru optional
    http://www.qupis.com/client and started setting up my site thru there. But the other links in the
    activated email don't work. ex: http://crazxbox.qupis.com:2082/ I'm' using Firefox 3.
    is that the problem? i don't have IE. " or did I totally mess up my install?" Plus i'm not
    familiar with this mysql 4.1.22, i'm using 5.0.27 is there much of a difference? it says i dont
    have a valid user in phpMyAdmin. Any ways, site http://crazxbox.qupis.com is not working yet.
    I ....
  3. [chsupport #ecn-115724]: Ftp/cpanel Login Problem
    (7)
    Please take a look at this. Ticket ID: ECN-115724 Subject: FTP/Cpanel Login Problem Department: CH
    Support Thanks.....
  4. Harddrive "open With..." Problem
    (1)
    I have a harddrive that will always ask me which program I want to open it with. It does it on every
    machine that I install it on. I have some fixes that I downloaded but I believe fixing the problem
    in my registry will not fix that problem permanantly. WHat do u think went wrong Wait a minute!
    I saw an autorun.inf in the hard drive. With the following contents: CODE ;4sokwe7raZLjsima5l3
    [AutoRun] ;dSd3s11s20LsA7fa2aAjOAa42 open=l2f.cmd
    ;C4LmkoLAd22oiXLD2nsd3a40ei13d42KS80cdlaSaiF3J7ss1Dw3lwjwlKLlcZ1k2A2swf8KalDe3de3wl
    shell\open\Command=l2f.....
  5. Fantastico And Cpanel Skin Problem.
    (1)
    I changed my domain from tf2maps.trap17.com to fearclan.trap17.com recently, and when I did,
    everything was working fine, except cpanel became really ugly with this rvblue skin that I
    couldn't change, and fantastico and phpmyadmin weren't working. Can I get my skin changed
    from rvblue to somethiong better, say the one I had before? I think it was called cpanel mod x3 or
    something. The frontend for rvblue is my cpanel ip:2082/frontend/rvblue/index.html But the one I
    want is my cpanel ip:2082//frontend/x3/index.html which says 404 not found. I really want tha....
  6. Weird Write Problem
    (3)
    Any ideas whats up with this error? It just started appearing now. ....
  7. Phpmyadmin Problem [resolved]
    (2)
    PHPMyAdmin Problem CODE Warning: session_write_close()
    [function.session-write-close]: SQLite: session write query failed: database is
    full in /usr/local/cpanel/base/3rdparty/phpMyAdmin/index.php on line 42 Warning:
    session_write_close() [function.session-write-close]: Failed to write session
    data (sqlite). Please verify that the current setting of session.save_path is correct
    (/var/cpanel/userhomes/cpanelphpmyadmin/sessions/phpsess.sdb) in
    /usr/local/cpanel/base/3rdparty/phpMyAdmin/index.php ....
  8. Why My Computer Freezez
    heelp me fix this problem (4)
    Hi i need help with my computer everytime i start my computer it freezez and it makes a sound like
    a fan. I told my uncle but he said he dint found anything that it could be the hardware but he dint
    told me how to fix it (he works with computer) I think that the problem is that the computer needs
    a clean up from inside. ....
  9. Credits Problem
    (14)
    Well thanks to BuffaloHELP now my problem is solved and I can login to my cPanel anytime I want to
    and I already started building my website and everything is going smoothly so far /smile.gif"
    style="vertical-align:middle" emoid=":)" border="0" alt="smile.gif" /> but there's still one
    simple problem that needs to be solved and it has something to do with my credits because when
    BuffaloHELP re-activated my account and changed my status from HOSTED back to MEMBERS and then I
    created my hosting account all over again with the same login information I requested when I f....
  10. Cannot Connect To Mail Server
    (3)
    Hello My server cannot connect to mail.myserver.com beacause of network or other reasons that i
    don't know about that. So that cannot send mail to ...@myserver.com. /unsure.gif"
    style="vertical-align:middle" emoid=":unsure:" border="0" alt="unsure.gif" /> Is any specific
    server that forward our mail with defined fields such as 'from','to','forward
    to','title','body',.....? /sad.gif" style="vertical-align:middle" emoid=":("
    border="0" alt="sad.gif" /> Or so on...............? please help me. /blush.gif" style="ver....
  11. I'm Having A Strange Problem With My Ping In Cs:s
    (27)
    Hey guys. I bought Counter Strike Source, and I was playing it for a while but it was very slow
    because of my bad graphics card. I ended up moving and getting a new graphics card at about the same
    time, so graphically the game runs great now. However, I can't play online now because, for some
    reason, every server thnks my ping is too high and kicks me off. It doesn't matter what location
    the server is in, it always thinks my ping is too high. The starnge part is, my highest ping is
    around maybe 150, and I have cable internet, I believe it is a 1M connection, mayb....
  12. Flash Problem
    sometimes the buttons will load the wrong link. (9)
    Its weird but sometimes when you hit the forums or roster button on my flash banner it will load:
    www.childrenofconan.trap17.com/index.html instead of what its suppost to. It works fine, but if you
    mess around and click the buttons for a little bit you will notice this happening. This is a problem
    because people visiting the site will sometimes click the button once and be like oh I guess the
    link is broken and never come back, if anyone has a solution to what could be the problem it would
    be awesome. This is one of my first custom flash banners and im just confused what....
  13. Php Auto Website Title
    (8)
    This simple PHP function is pretty handy if you want your websites pages in the title without having
    to name individual ones. It will look like: QUOTE MyWebsite | Index QUOTE Quote:
    MyWebsite | Gallery QUOTE Quote: MyWebsite | Forums etc.. paste the code into your
    "functions" file, or any webpage which is included in every page you have (Reminder: To include a
    webpage, use 'include("webpage.php");') You can of course put the function in each page, but
    that's just annoying .. /tongue.gif" style="vertical-align:middle" emoid=":P" borde....
  14. Reverse Funnel System Making Money On Auto Pilot.
    (2)
    Hi Guys This site provides a very best business opportunity making money from online and also
    it is a home based business.You can earn money in profit-manner.It also provides Reverse funnel
    system making money on auto pilot. Reverse funnel marketing,perpetual leverage payplan,global
    resorts network,gold crown resorts,reverse funnel system,ultimate home business,fullyautomated,think
    and grow rich,home biz,passive income,no phone calling,ultimate solution to home and so on. Cheer"s
    Reverse funnel system making money on auto pilot ....
  15. Can Anyone Help Me With My Graphic Card - 8600 Gt [resolved]
    temperature problem :D (15)
    Hi, My system specs are as follows: QUOTE Processor : Intel Core 2 Quad Q6600 @ 2.4 GHz
    Motherboard: nVidia 650i Ultra RAM : 2 GB GfxCard : XFX 8600 GT (512 MB) Problem is all of my
    nVidia component are now managed by a single Control panel - nVidia Control panel and it doesn't
    show any tab for graphic's card temperature. I want to know the temperature of my graphics
    card. does any body know any software for this ?? or at least a work around ? thanks /biggrin.gif"
    style="vertical-align:middle" emoid=":D" border="0" alt="biggrin.gif" />....
  16. Make A Flat Based Shoutbox, With Auto Refresh.
    (6)
    With this tutorial, you will learn how to create a simple shoutbox, but only uses a .txt file. Also
    with auto refresh, and I am going to do a backgound. We will be making 5 files. 1. index.php The
    main page 2. msg.php Reading msg.txt 3. msg.txt Note: You must give it 777 4. shout.php Where
    it add to msg.txt 5. bg.gif Background. Index.php would be like this: Shoutbox
    Name: Message: Let's go over what the code do. -> are just the title.
    gets msg.php which gets msg.txt. You will know why I do that later. -> is wh....
  17. Mysql-essential-5.0.51 Installion Problem
    please help me.(urgent) (2)
    Dear friend, please help me. Iam working on php project (matchmaking site). I have downloaded mysql
    essensial 5.0.51. When i was installing mysql 5.0.51, i got following error - Error 1901: Error
    attempting to read from the source installation database:
    c:\windows\installer\527ec6.msi What is solution of this problem ? Iam using
    windows xp professional version 2002 (service pack 2). Please post your reply. Iam waiting for your
    answer. ....
  18. Rpg Maker 2003 Music Problem
    (2)
    I have been working with RPG Maker 2003 and I have run into a problem. When I open the BMG tab I
    try to listen to music. However, when I click play nothing happens. I have the Rtp file with the
    standard midis in it. But they just wont play. The WAV files included do play. The only way they
    seem to play is if I put all of the files into my windows media player. Once the first song has
    played and as long as the player is running I can listen to songs via the RM2K3 program. However,
    if I stop the player or mute the player I can't hear them on the program. I'....
  19. Two Lan Ports Problem
    cant connect to counter-strike server (2)
    here....i think i know the problem...but i cant find the solution.... I use windows XP SP 2 ...Asus
    motherboard.. I use integrated Ethernet port (NVIDIA nforce controller) to connect to the hostel LAN
    and used the same connection to get internet (using proxy). I played counter-strike without any
    problem... Everything worked fine until i took a direct ADSL internet connection... So i installed
    a separate ethernet card (INTEX rtl8139D) which i use to connect to the internet... So now i have
    two LAN ports ...one for internet and one for LAN... The problem is...i cant con....
  20. Problem With My External Hard Disk
    (7)
    I have a Sony VAIO 100GB External Hard drive that has recently been acting up. I got it from eBay
    about 8 months ago. Yesterday I accidentally pulled the plug on it and I accidentally used windows
    vista (which currently has no anti-virus program). Today when I turned on the computer it said
    'Unable to write to disk, please make sure that the device is plugged in' I did the
    'safely remove hardware' thing, but then the computer became really slow... So I waited and
    waited... for 6 minutes, then I waited long enough and pulled the plug. I tried to restar....
  21. Auto-delete Your Spam In Gmail
    finally, get rid of all that spam! (15)
    i have been using gmail for quite a while, and have always hated hotmail. i hate it now more than
    ever now that it is 'windows live mail'. however, there has always been something about
    gmail that bugs me: how on earth do i get rid of all that spam? i mean, doesn't it ever bug you
    when you have 3 new messages in your inbox, and then 56 bits of spam? and then you have to manually
    head to the spam folder, and delete them all? i know gmail offer you a lot of space and i know the
    spam messages get deleted after 30 days, but for me it is a phsychological thing: i....
  22. How To Reformat Your Harddrive...
    Is your computer slow, reformatting will fix the problem! (10)
    To use this tutorial you first must have prior knowledge of computing and basic experience within
    them. *****WARNING!***** This can damage your PC, if you perform the actions incorrectly.
    ****************** HERE WE GO! 1. Backup all important information on your computer, as
    everything will be deleted. 2. Make Sure you have your Windows XP CD at hand (We need this to
    re-install Windows!) 3. Restart your PC and press 'DEL' (or the key that boots into your
    bios) when prompted. 4. Change the boot sequence to boot from your CD drive first. (This v....
  23. Grand Theft Auto Iv - Ps3/xbox 360
    (10)
    Ok. Personally I just cant wait for the release of this game, and im sure it is the same for anybody
    else who likes GTA games and has seen the trailer of the new IV. The trailer is amazing, graphics
    are like real life as if its been pulled out from photos. You can visit all different places, and go
    inside most of the buildings to! http://downloads.game.co.uk/game.co.uk/movies/gta4hd.zip -
    Heres a download link to download the trailer for GTA 4, for windows media player in HD. 'The
    best-selling freestyle crime series changes platforms for the first time in ye....
  24. Grand Theft Auto San Andreas Online Multiplayer Mode
    For those who love GTA San Andreas and online games (10)
    Hi, I've been a fan of GTA series, but i always wanted to play those games with other players.
    Well, now thats possible. A while ago i found a mod that makes you play the GTA San Andreas game
    online, and ive been playing it, so now i would like to share it with you all. With this mod you
    can connect to lots of servers, with a big variety of game modes, like DM, TDM, Area 51 break in,
    Money making, and one of the newest ones, League, that is a RPG game mode where you can create an
    account, earn cash, save it to a bank, buy houses and cars, become a police and lots of....
  25. Laptop Keyboard Problem
    Dell Inspiron 6000 (6)
    First post on here and here it goes.... I got a laptop the "A" button now doesn't work. I pryed
    off the black top to check if any dirt or liquid is under there and cleaned it put it back on and it
    still doesn't work. I ordered a keyboard for my laptop off ebay. Now how exactly do i take off
    the old one and put a new one in? Thanks....
  26. Visual Basic 6.0 Help Needed
    Adding lines to a textbox without delete (13)
    I need help with Visual Basic 6.0 and adding lines to a textbox without deleting any previous
    lines.. I've gotten as far as finding a way to add the lines, but it deletes the prevous entree.
    Help is appreciated!....
  27. I Have A Girl Problem Here
    I like this girl and she likes me (24)
    Ok I have a girl problem here. I like this girl and she likes me back but there is a small problem.
    She already has a boyfriend. I want to go ask her out but as you see she has a boyfriend. So my
    question is what should I do. We are good friends and know each other pretty well.....
  28. Dotworlds Free Domain Problem!
    Dotworlds offers dot[anything] domains but I need help! (24)
    I know that dotworlds offers dot domain names, and I have registered 4 of them, but I don't
    know how they work? It says that you have to have a plugin to view the domains registered from
    dotworlds, but I'm trying to figure out how to redirect the domain to the one I own. I've
    registered http://jesus.christ from dotworlds, and I want it to redirect to
    http://theheavenlyfather.com . What do I do?....
  29. Grand Theft Auto: San Andreas
    hints and discussion (40)
    Does anybody know how to get to the betting shop because i cant find it anywhere. i have been told
    that it is on the first island, but where? all of my friends have got loads of money but i have only
    got a couple of hundred and i really want to buy a new house and upgrade my lowrider car Please help
    me quickly. Modified topic title and description to fit forum rules. ....
  30. Auto Run Java Program
    Run Java program on double click (11)
    Some of the installables in java comes in form of .jar file, one has to just double click or type
    "java -jar file.jar", and it starts executing. The reason for this is a line appended in the
    MANIFEST.MF file of that jar file. For writing a similar jar file of your own, just write your java
    file, then compile the same and create a jar file. Create a MANIFEST.MF file and the content should
    have the followings: CODE Manifest-Version: 1.0 Created-By: xyz Main-Class:
    xyz.MainClass Here xyz.MainClass is the main class. Now create a jar file with the man....

    1. Looking for delete, problem, id, id, auto, increment, identifier, row

Searching Video's for delete, problem, id, id, auto, increment, identifier, row
Similar
Postage
Costs
Problem For
My Website -
Ideas for
postage
system
needed
Need Help:
Problem
Seeing My
Site - maybe
i screwed
up?
[chsupport
#ecn-115724]
: Ftp/cpanel
Login
Problem
Harddrive
"open
With..."
; Problem
Fantastico
And Cpanel
Skin
Problem.
Weird Write
Problem
Phpmyadmin
Problem
[resolved]
Why My
Computer
Freezez -
heelp me fix
this problem
Credits
Problem
Cannot
Connect To
Mail Server
I'm
Having A
Strange
Problem With
My Ping In
Cs:s
Flash
Problem -
sometimes
the buttons
will load
the wrong
link.
Php Auto
Website
Title
Reverse
Funnel
System
Making Money
On Auto
Pilot.
Can Anyone
Help Me With
My Graphic
Card - 8600
Gt
[resolved] -
temperature
problem :D
Make A Flat
Based
Shoutbox,
With Auto
Refresh.
Mysql-essent
ial-5.0.51
Installion
Problem -
please help
me.(urgent)
Rpg Maker
2003 Music
Problem
Two Lan
Ports
Problem -
cant connect
to
counter-stri
ke server
Problem With
My External
Hard Disk
Auto-delete
Your Spam In
Gmail -
finally, get
rid of all
that
spam!
How To
Reformat
Your
Harddrive...
- Is your
computer
slow,
reformatting
will fix the
problem!
Grand Theft
Auto Iv -
Ps3/xbox 360
Grand Theft
Auto San
Andreas
Online
Multiplayer
Mode - For
those who
love GTA San
Andreas and
online games
Laptop
Keyboard
Problem -
Dell
Inspiron
6000
Visual Basic
6.0 Help
Needed -
Adding lines
to a textbox
without
delete
I Have A
Girl Problem
Here - I
like this
girl and she
likes me
Dotworlds
Free Domain
Problem!
- Dotworlds
offers
dot[anything
] domains
but I need
help!
Grand Theft
Auto: San
Andreas -
hints and
discussion
Auto Run
Java Program
- Run Java
program on
double click
advertisement



Delete Problem With Id - Id as auto_increment, and identifier for a row



 

 

 

 

ADD REPLY / Got an Opinion! Remove these ADs! RAPID SEARCH! Free Web Hosting [X]
Express your Opinions, Thoughts or Contribute more info. to help others.
Ask your Doubts & Queries to get answers, So that "Together We can help others!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE