PDA

View Full Version : insert new row to table in php Mysql



sujith787
07-27-2007, 06:54 PM
hi

i have problem with inserting rows into my table....

my table "customer" is

name age phone
-------------------------------------
sam 19 24252
john 67 82737
george 89 23872


here i have a problem. i.e i want the latest inserted row should be in top. i mean latest row should be the first row.

but when i insert new rows it get placed in random position
sometimes ---> at the end of the table i.e last row
sometimes -----> at the begging of the table i.e first row
sometimes -----> middle of the table i.e somewhere in middle rows

how can i avoid this and make the insertion uniformly.
that measn latest inserted row should be in top (first row)

plz help me.
how can i

superjadex12
08-08-2007, 07:04 AM
I have a way to do it. it may not be the easiest/best way, but it WILL give you what you want:

Just record the date and time that each row gets inserted and order by the date. I did a quick google search and found :

http://www.plus2net.com/sql_tutorial/date-inserting.php

that shows you how to record the current date and time. Then when displaying, just throw in a ORDER BY at the end of your query.

HTH

jr_yeo
09-04-2007, 02:05 AM
noted.

boogyman
09-04-2007, 12:30 PM
to view the table with the newest customers on top you would do something like this as your query



"SELECT 'name','age','phone' FROM customer WHERE _______ ORDER BY 'dt_created' DESC"

You would need to add a field to your table that will insert the present time on the server, and change "dt_created" to whatever you name that field.
And you will need to put in the blank space the evaluation you wish to perform.