how to create a text box that generates auto number

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • laniebalbido
    New Member
    • Feb 2007
    • 1

    how to create a text box that generates auto number

    hi , im a new in php. id like to know how to create a textbox that generates auto number for every new record to be inserted.

    thanks
    Last edited by laniebalbido; Feb 28 '07, 05:18 AM. Reason: misspelled
  • snapple
    New Member
    • Feb 2007
    • 11

    #2
    you are a little vauge but I believe all you need is a counter.

    say $count=0 then when you need a new text file, say $count++

    This probably isn't what you are actually asking for, but i'm a little confused on your question.

    Comment

    • ronverdonk
      Recognized Expert Specialist
      • Jul 2006
      • 4259

      #3
      What "record to be inserted" are you talking about?
      A database, a text file, ???

      Ronald :cool:

      Comment

      • routinet
        New Member
        • Jan 2007
        • 2

        #4
        You do not need to do this. When you insert the record, the database will automatically generate the autonumber required and report it back to you. It is much easier to report this information AFTER the insert has been done.

        If you want to report it before the insert, then you actually have to insert a blank record to 'reserve' the autonumber. Without the proper care, this leaves blank records, incomplete data, or non-sequential records in your database. In other words, you can get the autonumber before inserting, but you have to make sure you are managing it correctly.

        Comment

        • ronverdonk
          Recognized Expert Specialist
          • Jul 2006
          • 4259

          #5
          If you want to know the next insert id before having done the actual insert, use MySQL's own table status and try the following code:
          [php]<?
          $tablename = "tablename" ;
          $next_increment = 0;
          $qShowStatus = "SHOW TABLE STATUS LIKE '$tablename'";
          $qShowStatusRes ult = mysql_query($qS howStatus) or die ( "Query failed: " . mysql_error() . "<br/>" . $qShowStatus );

          $row = mysql_fetch_ass oc($qShowStatus Result);
          $next_increment = $row['Auto_increment '];

          echo "next increment number: [$next_increment]";
          ?> [/php]

          Ronald :cool:

          Comment

          Working...