SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Guru adammc's Avatar
    Join Date
    Aug 2004
    Location
    Cairns, Australia
    Posts
    762
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Generate Random Id / Unique Id

    Hi Folks,

    I am creating an affiliate system for a website and am a bit stuck as to how to generate a unique id for each affiliate when they register.

    In my mysql table I will have a unique 'id' (auto inc) and I then want to have an affiliate_id column. Can I get the DB to give auto increment the id numberr using these letters beforfe the id number 'aff-'

    example:

    aff-1
    aff-2
    aff-3

    Or should I use php to generate this?

  2. #2
    SitePoint Wizard silver trophy
    Join Date
    Mar 2006
    Posts
    6,132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    is there some functional reason why you need to prefix the id with aff-?
    i would recomend you just store them in the database as a number.

    if you need to add that for display purposes, just
    PHP Code:
    // outputting
    echo 'aff-' $id;

    //and strip when retrieiving 
    $id substr($_GET['id'], 4strlen($_GET['id'])); 


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
  •