MySql Help

Discussion in 'PHP' started by imchandan, Apr 1, 2008.

  1. #1
    Hey guys,
    i have a table which has id(unique key) and data..
    while displaying one record(row), i need to display the unique key(id) of next record..please help.
     
    imchandan, Apr 1, 2008 IP
  2. singh.ajit05

    singh.ajit05 Peon

    Messages:
    83
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    for this you can use auto increment id..

    CREATE TABLE `yourneed` (
    `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
    `name` VARCHAR( 80 ) NOT NULL
    ) ENGINE = innodb;

    Here id is auto increment and also unique it never be duplicate..

    You just have to insert value in only name field........
     
    singh.ajit05, Apr 2, 2008 IP
  3. imchandan

    imchandan Guest

    Messages:
    50
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    43
    #3
    hi ajit,
    i understand that this could solve my problem. but i already have a huge database. do you want me to edit the table and add Id column?
     
    imchandan, Apr 2, 2008 IP
  4. singh.ajit05

    singh.ajit05 Peon

    Messages:
    83
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    if you dont have have auto increment field any,, you can convert it into auto increment number
     
    singh.ajit05, Apr 2, 2008 IP
  5. CreativeClans

    CreativeClans Peon

    Messages:
    128
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #5
    This depends on what your problem is. Do you want to show the id of the next record already present in the table? Or do you want to show the id that would be used if you inserted a new record in the table?

    If you want to show the id of the next record already present in the table, an autoincrement field does not solve anything, unless you never ever delete any records.
     
    CreativeClans, Apr 2, 2008 IP
  6. vishnups

    vishnups Banned

    Messages:
    166
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Do you mean to say that in the page showing a record, you need to have a link which when clicked takes you to the next result??? This has nothing to do with auto-increment. There will always be a unique id for a record, it need not have to be a auto-increment. This can be done with some php coding. Even if you have a large DB, you can add a auto-increment field, if necessary. If you need any help you can PM me...
     
    vishnups, Apr 2, 2008 IP
  7. singh.ajit05

    singh.ajit05 Peon

    Messages:
    83
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Yes it may be true, that in this case autoincrement id is not necessary, we can do it by getting a max row of entire table and incrrease it by 1 and insert this value........
     
    singh.ajit05, Apr 5, 2008 IP