SitePoint Sponsor |
|
User Tag List
Results 1 to 7 of 7
Thread: Inserting into database question
-
Feb 24, 2001, 13:42 #1
- 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.
-
Feb 24, 2001, 14:19 #2
- 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
-
Feb 25, 2001, 11:21 #3
- 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
-
Feb 25, 2001, 13:18 #4
- 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.
-
Feb 25, 2001, 15:48 #5
- 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?
-
Feb 26, 2001, 18:57 #6
- 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
-
Feb 27, 2001, 04:55 #7
- 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;
Good luck!
... what's the world coming to?
Bookmarks