Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

PHP/MYSQL next ID

Options
  • 01-07-2003 10:36pm
    #1
    Closed Accounts Posts: 1,114 ✭✭✭


    I'm new to PHP/MySQL and am making a test site for myself what i want to know is a way to get the next avaiable database id from a mysql DB

    Thanks


Comments

  • Registered Users Posts: 1,186 ✭✭✭davej


    From the type of question you are asking my guess is that there is something wrong with your design.

    You are asking is it possible to get the value of the ID generated if you were to do the next INSERT?

    I don't think it is possible or desireable to do such a thing. You should be thinking about how to use the LAST_INSERT_ID() function instead.

    davej


  • Closed Accounts Posts: 5,564 ✭✭✭Typedef


    Ideally what you want is a table constructed like this

    Table 1
    [some_field] -- an index, (the only index in fact), and autoincrements this would be a serial field in PostgreSQL (not sure about MySQL, check google)

    [some_other_field] -- holds data
    [another filed] -- holds data

    and so on

    Table 2

    [some_field_table2] -- an index (the only index on table 2)
    [field_blah]
    [field_table_1_index_ref] holds a number, which is the unique number stored in some_field on table 1.
    So when you reference table 1, from data in table 2, you do so by referencing an index on the table, fast and efficient.

    Again, investigate data types which autoincrement in MySQL, this should be the data type of your index on table 1.

    At least, that's how I'd do it....
    maybe


  • Registered Users Posts: 944 ✭✭✭nahdoic




Advertisement