tags:

views:

125

answers:

4

Hello, I am using MySQL and PHP. I am having a problem with inserting a new item at the end of my table. When I insert the new item appears after the last created item, but I want it to be entered at the bottom of the table. Suppose that I have a table id=int,Primary Key and album=string and the table is:

  1. Wrath
  2. Crack The Skye
  3. Enter Shikari

What would the MySQL query be if php variable $album=myAlbum was to be inserted next, at the end of the table, and with the appropriate id? Thanks

+12  A: 

You have to understand what database is.
There is no "end" in the database.
The rows take order only at the SELECT time.

So, you have to add ORDER BY clause to your SELECT query to make rows in the desired order.

You may add another field to order your table by or use existing one.

Col. Shrapnel
A: 

I am confused - the order in the table does not matter. If you need a specific ordering, then query the data using an ORDER BY clause.

Justin Ethier
+1  A: 

you want the id column to be auto_increment. this will give the behaviour you're looking for.

oedo
+3  A: 

You should define the id with autoincrement so that mysql will keep a counter that grows on each insert. That way you can order by id to know in which order stuff went in

baloo