Loading ...
Sorry, an error occurred while loading the content.

Re: [bang-phpug] Need Auto - increment function for the ID field

Expand Messages
  • Tapan Shah
    If you can afford creating a record in the backend beforehand, use autoincrement for the field in mysql and then, using this function mysql_insert_id(), you
    Message 1 of 3 , Oct 22, 2007
    • 0 Attachment
      If you can afford creating a record in the backend beforehand,

      use autoincrement for the field in mysql and then, using this function
      mysql_insert_id(), you can fetch the freshly create unique id.

      On 10/22/07, dhana_1706 <dhana_1706@...> wrote:
      >
      > Hi,
      >
      > I have an requirement in my project which is as follows,
      >
      > we used one field called listingID,it is unique field ,used as
      > primary key..
      >
      > In my project,i have to insert the listingID along with other values
      > every time while creating the record using web page..
      >
      > For this, i have taken the max(listingID) from table and incremant
      > the ID + 1 and written the Query to insert the values along with
      > listingID.
      >
      > Now we want the requirement as follows,
      >
      > we need to have function for the auto increment for the listingID,
      > means every time while creating or saving the record,listingID should
      > be automatically generated instead of every time taking maxid and
      > increment it and inserting to table.
      >
      > If anybody know the solution to auto increment for the ID ,plz help
      > me..
      >
      > Thank u,
      > Dhana.
      >
      >
      >



      --
      Tapan Shah
      http://www.tapan.in/
      http://www.assetonline.in/


      [Non-text portions of this message have been removed]
    • guruj_r
      Hi, Thanks for the reply. We have made the field as auto increment . We have also used two functionalities - mysql_insert_id() and last_insert_id() to
      Message 2 of 3 , Oct 23, 2007
      • 0 Attachment
        Hi,

        Thanks for the reply.

        We have made the field as "auto increment". We have also used two
        functionalities - mysql_insert_id() and last_insert_id() to retrieve
        the last created id.

        But can you tell me whether the above two syntax will have any
        issue in a web project? Meaning we are going to use it in multi user
        environment - so more than one user can create record.

        So the last_insert_id or mysql_insert_id() will give the id that
        was created lastly from my system alone or the lastly created id
        from any system in that table?

        For your reference - i got the info from the help file as

        +++++++++++

        "LAST_INSERT_ID(), LAST_INSERT_ID(expr)

        Returns the first automatically generated value that was set for an
        AUTO_INCREMENT column by the most recent INSERT or UPDATE statement
        to affect such a column.

        mysql> SELECT LAST_INSERT_ID();
        -> 195

        The ID that was generated is maintained in the server on a per-
        connection basis. This means that the value returned by the function
        to a given client is the first AUTO_INCREMENT value generated for
        most recent statement affecting an AUTO_INCREMENT column by that
        client. This value cannot be affected by other clients, even if they
        generate AUTO_INCREMENT values of their own. This behavior ensures
        that each client can retrieve its own ID without concern for the
        activity of other clients, and without the need for locks or
        transactions."

        +++++++++++++

        Any help would be helpful...

        Regards,
        Guru

        --- In bang-phpug@yahoogroups.com, "Tapan Shah" <tapsboy@...> wrote:
        >
        > If you can afford creating a record in the backend beforehand,
        >
        > use autoincrement for the field in mysql and then, using this
        function
        > mysql_insert_id(), you can fetch the freshly create unique id.
        >
        > On 10/22/07, dhana_1706 <dhana_1706@...> wrote:
        > >
        > > Hi,
        > >
        > > I have an requirement in my project which is as follows,
        > >
        > > we used one field called listingID,it is unique field ,used as
        > > primary key..
        > >
        > > In my project,i have to insert the listingID along with other
        values
        > > every time while creating the record using web page..
        > >
        > > For this, i have taken the max(listingID) from table and
        incremant
        > > the ID + 1 and written the Query to insert the values along with
        > > listingID.
        > >
        > > Now we want the requirement as follows,
        > >
        > > we need to have function for the auto increment for the
        listingID,
        > > means every time while creating or saving the record,listingID
        should
        > > be automatically generated instead of every time taking maxid and
        > > increment it and inserting to table.
        > >
        > > If anybody know the solution to auto increment for the ID ,plz
        help
        > > me..
        > >
        > > Thank u,
        > > Dhana.
        > >
        > >
        > >
        >
        >
        >
        > --
        > Tapan Shah
        > http://www.tapan.in/
        > http://www.assetonline.in/
        >
        >
        > [Non-text portions of this message have been removed]
        >
      Your message has been successfully submitted and would be delivered to recipients shortly.