cant figure out how to increase the id...

Discussion in 'PHP' started by killaklown, Oct 12, 2006.

  1. #1
    i have:
    $i=0;
    $i++;

    but how can i make it so that $i++ will increase for each of the new table rows?
    IE:

    ID | Name
    1 | Test
    2 | Another Test

    Right now it will just show:

    ID | Name
    1 | Test
    1 | Another Test

    (the information is coming from my database)


    Edit: nvm, had $i=0; in the wrong spot... heh
     
    killaklown, Oct 12, 2006 IP
  2. Barti1987

    Barti1987 Well-Known Member

    Messages:
    2,703
    Likes Received:
    115
    Best Answers:
    0
    Trophy Points:
    185
    #2
    If you are using the database, use auto increment instead.

    Peace,
     
    Barti1987, Oct 12, 2006 IP
  3. gigamike

    gigamike Active Member

    Messages:
    165
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #3
    hi killaklown,

    if youre using a databse, use the auto icrement feature of it. here is an example taken from MySQL database.

    CREATE TABLE `users` (
    `id` int(5) NOT NULL auto_increment,
    `username` varchar(10) NOT NULL default '',
    `password` varchar(10) NOT NULL default '',
    `lastname` varchar(35) NOT NULL default '',
    `firstname` varchar(35) NOT NULL default '',
    `email` varchar(35) NOT NULL default '',
    PRIMARY KEY (`id`)
    )

    once you insert new record to your database, it will automatically provides you with an incremented id

    thanks,

    gigamike
     
    gigamike, Oct 13, 2006 IP