Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    May 2010
    Posts
    22
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Sql table problem

    HY every one , i am having problem with my phpmysql database , i save different values form form but when i save multi values at a time the values saved in database successfully but the sequence of my praimary id changes , e.g

    id firstname lastname dob
    1 abc abc abc
    3 abc abc abc
    2 abc abc abc
    4 abc abc abc
    5 abc abc abc

    so own but as you see 2 must be before the value 3 so any one tell me what is the problem in database ?

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,613
    Thanks
    80
    Thanked 4,635 Times in 4,597 Posts
    You seem to be under the assumption that records in a database are *ORDERED* the same as their ID or primary key.

    Not so.

    The records can (and often are) stored in random order.

    If you want them in a particular order, you MUST use the ORDER BY clause in your SQL SELECT statement.

    That is:
    Code:
    SELECT * FROM yourtablename ORDER BY id
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #3
    New Coder
    Join Date
    May 2010
    Posts
    22
    Thanks
    2
    Thanked 0 Times in 0 Posts
    you are right but how to save this qurey in sql forever it just runs only one times and when i exit from sql table the qurey is set to defalt which again jumble up some values as i have auto incriment checked but stil my primary key which is "id" save up and down in the table which creats problem in other scripts that i have made help me plzzzz.

  • #4
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    Your other scripts also need to order the results correctly when they query the database.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •