php/mysql question

x-anubis-x

TH.net Regular
Reaction score
4
hey i was wondering what the php code would look like if i wanted to insert a row into the first position of a mysql table rather than the last.

for example if i had the rows:
blue
red
white
black

and i wanted to insert green it would be placed in the first row so then the list would look like:
green
blue
red
white
black
 

mase

____ ___ ____ __
Reaction score
154
Have you check http://php.net?
I think there is a way to do that with a SQL query, but I'm not sure.
 

phyrex1an

Staff Member and irregular helper
Reaction score
446
A database table has no such thing as an 'order', or more correctly in a database table the order of the rows is irrelevant, thus there is no way to specify where a new row is going to end up.

You can however sort the rows as you want in your query using ORDER BY <field>, adding a 'position' field to your table maybe is what you want?
 

DDRtists

ɹoʇɐɹǝpoɯ ɹǝdns
Reaction score
415
For the Newest first:

"SELECT * FROM table ORDER BY id DESC"

or the oldest first:

"SELECT * FROM table ORDER BY id ASC"

The easiest way to sort is making an table ID, making it auto increase, and making it the index.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top