Results 1 to 4 of 4

Thread: insert new row to table in php Mysql

  1. #1
    Join Date
    Jul 2007
    Posts
    37
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default insert new row to table in php Mysql

    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

  2. #2
    Join Date
    Jul 2006
    Posts
    36
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    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

  3. #3
    Join Date
    Apr 2006
    Posts
    429
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    noted.
    Please don't mind me. I am just posting a lot of nonsense.

  4. #4
    Join Date
    Jul 2006
    Location
    just north of Boston, MA
    Posts
    1,806
    Thanks
    13
    Thanked 72 Times in 72 Posts

    Default

    to view the table with the newest customers on top you would do something like this as your query

    Code:
    "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.

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
  •