SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Member
    Join Date
    Feb 2001
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    if i insert a new row in the table and set the id to zero, will this automatically move the other entries down a notch. I mean does it make the row at zero equal to one, and increments the other rows.

    If not how would i do this.

  2. #2
    SitePoint Evangelist
    Join Date
    May 2000
    Location
    Canada
    Posts
    533
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    no, it wont move other ID's down a notch .. see the previous message i just replied to, you can order then in a specific order
    cogito, ergo sum

  3. #3
    SitePoint Author Kevin Yank's Avatar
    Join Date
    Apr 2000
    Location
    Melbourne, Australia
    Posts
    2,571
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    In principle, you shouldn't be relying on an autoincrement column to do anything except provide a unique number for each entry in the table. If you are, you might need to reconsider your database design.
    Kevin Yank
    CTO, sitepoint.com
    I wrote: Simply JavaScript | BYO PHP/MySQL | Tech Times | Editize
    Baby’s got back—a hard back, that is: The Ultimate CSS Reference

  4. #4
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I posted something a couple of days ago that may be of assistance.

    http://www.sitepointforums.com/showt...153#post119153

    To iterate, it is a misnoma to assume that mySQL or any RDMS will maintain any order to the records in a table. Its not part of the relational data model. Its up to the RDMS as to how it stores your records which may include all sort of hashing algorithms and physical storage management strategies that I understand squat about . However, when you want to view your data you can specify how it is to be ordered by using ORDER BY in your SQL query.

    I had a bit of a debate with freddydoesphp a while ago on using auto_increment to maintain order. But I can see now that his adherence to a principle of design is warranted. I've notice that a lot of people assume that the RDMS is maintaining some sort of order.

  5. #5
    SitePoint Addict
    Join Date
    Nov 2000
    Location
    London, UK
    Posts
    223
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What are you trying to do with this? I mean ... there's lots of ways to get around a problem, and possibly with a bit more info, someone could help you?

    ... what's the world coming to?

  6. #6
    SitePoint Member
    Join Date
    Feb 2001
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    oh the reason im trying to do this is because i wanted to set up a news page on my site. but i read a couple tutorials on the web but they all displayed the rows of the data base from first to last, which wouldnt make sense if i wanted to show my viewers the latest news first.

    i discovered kevin yanks tutorial and i think i'll keep referencing it because i see it has been well written
    anyways thanks alot everyong.

    leerie

  7. #7
    SitePoint Addict
    Join Date
    Nov 2000
    Location
    London, UK
    Posts
    223
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Probably the easiest way to do this is to just insert an extra field in your database called Created (or whatever else you want), and put the date into it with PHP. Then, you can just do:

    Code:
    SELECT * FROM news
    ORDER BY Created DESC;
    which should get you them from newest to oldest. Also, if you've got a lot of news afterwards, you could only have it get the five newest days worth or something like that.
    Good luck!

    ... what's the world coming to?


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
  •