SitePoint Sponsor

User Tag List

Results 1 to 11 of 11

Thread: auto_increment

  1. #1
    Currently Occupied; Till Sunda Andrew-J2000's Avatar
    Join Date
    Aug 2001
    Location
    London
    Posts
    2,475
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question auto_increment

    When I delete a row in mySQL, it doesn't set the increment back, so i have gaps, in the id's. How could I make the auto_increment go like this

    • 1,2,3,4,5,6,7,8,9,10


    instead of

    • 1,3,4,7,8,10

  2. #2
    Currently Occupied; Till Sunda Andrew-J2000's Avatar
    Join Date
    Aug 2001
    Location
    London
    Posts
    2,475
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok I just found this which helps, but how do put I back all id's in between and from the beginning?

    mysql_insert_id
    (PHP 3, PHP 4 >= 4.0.0)

    mysql_insert_id -- Get the id generated from the previous INSERT operation

  3. #3
    You talkin to me? Anarchos's Avatar
    Join Date
    Oct 2000
    Location
    Austin, TX
    Posts
    1,438
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can't, don't worry about it.
    ck :: bringing chris to the masses.

  4. #4
    Currently Occupied; Till Sunda Andrew-J2000's Avatar
    Join Date
    Aug 2001
    Location
    London
    Posts
    2,475
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    would i be best using my own id method then, as i'm sure it aint too hard to do that or is it even worth bothering?

  5. #5
    SitePoint Wizard silver trophy redemption's Avatar
    Join Date
    Sep 2001
    Location
    Singapore
    Posts
    5,269
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    it'd be only worth bothering if you need to display the id's and they absolutely needed to be in order with no gaps... but that's stating the obvious isn't it?

  6. #6
    You talkin to me? Anarchos's Avatar
    Join Date
    Oct 2000
    Location
    Austin, TX
    Posts
    1,438
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Even this it's not worth bothering, you can just maintain a counter variable separately that you increment after you display each row.
    ck :: bringing chris to the masses.

  7. #7
    SitePoint Wizard silver trophy redemption's Avatar
    Join Date
    Sep 2001
    Location
    Singapore
    Posts
    5,269
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    but what if each record had an id that it needed to have instead of being arbitrarily assigned one when it is retrieved?

  8. #8
    Currently Occupied; Till Sunda Andrew-J2000's Avatar
    Join Date
    Aug 2001
    Location
    London
    Posts
    2,475
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok, im confused how to make my forum now.

    I need to store each thread under an id, so how do, i store which post goes to which thread/topic. can someone help me get back on track please.

    thanks

  9. #9
    SitePoint Wizard silver trophy redemption's Avatar
    Join Date
    Sep 2001
    Location
    Singapore
    Posts
    5,269
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    just use the id MySQL assigns to your auto_increment field... in this case it does not matter if the ids don't follow in sequence

  10. #10
    Currently Occupied; Till Sunda Andrew-J2000's Avatar
    Join Date
    Aug 2001
    Location
    London
    Posts
    2,475
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes, but this is what im confused on now, do i create a table for each topic, or thread? At the moment i'm tied up with other things and cant get focused on this right now, but i need starting point to get back on track, when i have time.

  11. #11
    Mlle. Ledoyen silver trophy seanf's Avatar
    Join Date
    Jan 2001
    Location
    UK
    Posts
    7,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    MySQL does that incase you delete, for example, a thread and accidently leave all of the posts for that thread in another table with that id. If MySQL went back to use the id you have deleted all of the old posts would be assoiated with the new thread

    Have one table to hold all threads and one to hold all posts. Use the primary key from the threads table as a forein key in the posts table

    Sean
    Harry Potter

    -- You lived inside my world so softly
    -- Protected only by the kindness of your nature


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •