SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: ID Genration??

  1. #1
    SitePoint Member
    Join Date
    Feb 2008
    Posts
    23
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    ID Genration??

    hi
    NightStalker-DNS was ask me which kind of ID u want to generate?
    so ,i have one form on which Id field when newUser open this registration form
    and gets his new ID such as 23,37,1,8.....,according to number of users fill this form, also it need to avoid duplication

  2. #2
    SitePoint Mentor NightStalker-DNS's Avatar
    Join Date
    Jul 2004
    Location
    Cape Town, South Africa
    Posts
    2,878
    Mentioned
    47 Post(s)
    Tagged
    0 Thread(s)
    Hi

    Well, the best way to do it would be to use a database with an autogenerated int field.

    The ID field should be in the same table as you store successful registrations.

    Then when the page loads, u can insert a blank row into the db so it generates the ID and returns in to you, then when the user clicks save it does an update statement on that ID.

    This is not full proof coz you will have a lot of blank rows in ur db if the user does not complete the registration.

    Alternatively you can create a random number on the page load and check if that already exists in the DB and if so, generate another one.

    I hope this makes sense.

    To generate a random number u can do this:

    Random ran = new Random();
    int id = ran.Next(MaxNumber);

    Let us know if you have any further questions

  3. #3
    SitePoint Mentor NightStalker-DNS's Avatar
    Join Date
    Jul 2004
    Location
    Cape Town, South Africa
    Posts
    2,878
    Mentioned
    47 Post(s)
    Tagged
    0 Thread(s)
    Sorry, double post.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •