1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

PHP Newbie question

Discussion in 'MySQL' started by Jim_Westergren, Aug 28, 2005.

  1. #1
    Hi,

    I will now make a table in MySQL and which will generate a HTML table with a list with PHP. This I know how to do. I also know how to do the form for inputting data in the db.

    Now I would like that each entry gets an ID number. The first one #1 and then +1 after each input by the form. How do I do that?

    The purpose of it is that I can change in the db by writing the ID number of the entry to be changed.

    Thanks.
     
    Jim_Westergren, Aug 28, 2005 IP
  2. blinxdk

    blinxdk Peon

    Messages:
    660
    Likes Received:
    27
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Add the ID field to your mysql database, then select the result set using ORDER BY youridfield ASC;

    That will order the result with the lowest numbers first, you can use DESC to reverse it.

    If you want the entry in the database to automaticly get the idfield when you add it, you can assign it as autoincrement.
     
    blinxdk, Aug 28, 2005 IP
  3. Jim_Westergren

    Jim_Westergren Notable Member

    Messages:
    1,882
    Likes Received:
    247
    Best Answers:
    0
    Trophy Points:
    235
    #3
    That I knew actually, but how do I get the ID numbers into the db? Or is that automatic?
     
    Jim_Westergren, Aug 28, 2005 IP
  4. blinxdk

    blinxdk Peon

    Messages:
    660
    Likes Received:
    27
    Best Answers:
    0
    Trophy Points:
    0
    #4
    If you're just creating the table, add an autoincrementing field.

    If you have an existing table then use ALTER table ADD COLUMN.

    Look here for more info: http://dev.mysql.com/doc/mysql/en/example-auto-increment.html

    If you are using some tool to manage your db, then it proberly has functions for all of the above.
     
    blinxdk, Aug 28, 2005 IP
    Jim_Westergren likes this.
  5. Jim_Westergren

    Jim_Westergren Notable Member

    Messages:
    1,882
    Likes Received:
    247
    Best Answers:
    0
    Trophy Points:
    235
    #5
    Thank you blinxdk.

    I will do the table now so the autoincrementing is the way to go. Will learn it now.

    Thanks.
     
    Jim_Westergren, Aug 28, 2005 IP