Discover Habbo's history
Treat yourself with a Secret Santa gift.... of a random Wiki page for you to start exploring Habbo's history!
Happy holidays!
Celebrate with us at Habbox on the hotel, on our Forum and right here!
Join Habbox!
One of us! One of us! Click here to see the roles you could take as part of the Habbox community!


Results 1 to 4 of 4
  1. #1
    Join Date
    Feb 2006
    Location
    Scotland
    Posts
    2,087
    Tokens
    138

    Latest Awards:

    Default Alphanumeric Generator?

    Hey,

    Right now I am using (http://www.i-fubar.com/random-string-generator.php) but I need to generate the string so it can be used as a Ticket ID.

    The only thing is, this ID needs to be unique to the ticket - So how would I go about generating a unique alphanumeric string?

    It needs to be like this: LSOK32-HSJK39 (So 6 characters, hyphen then another 6 characters)

    I only just realised that the thing generated might not be unique so thats why I am posting.

    Simply, My idea was:

    Generate
    Check if it is already in DB
    If so, Regenerate
    Else, set it to the query

    The only thing is, I dont know how to get the hyphen in and how to regenerate the code?

    This sounds all a bit stupid and I presume its pretty easy to do!

    Ill try to +Rep all useful answers

    Moved by Invent (Forum Moderator) from Designing & Development: Please post in the correct forum next time, thanks .
    Last edited by Invent; 07-08-2008 at 06:59 PM.

  2. #2
    Join Date
    May 2005
    Location
    San Francisco, CA
    Posts
    7,160
    Tokens
    2,331

    Latest Awards:

    Default

    PHP Code:
    <?php

    $let 
    = array( "a""b""c""d""e""f""g""h""i""j""k""l""m""n""o""p""q""r""s""t""u""v""w""x""y""z" );

    $random $letrand(025) ] . $letrand(025) ] . $letrand(025) ] . $letrand(025) ] . rand(09) . rand(09) . '-'$letrand(025) ] . $letrand(025) ] . $letrand(025) ] . $letrand(025) ] . rand(09) . rand(09);

    $random strtoupper$random );

    echo 
    $random;

    ?>
    That's one way to generate a random string.

    To keep checking & regenerating just make it a function like this:

    PHP Code:
    function generate()
    {


        
    $let = array( "a""b""c""d""e""f""g""h""i""j""k""l""m""n""o""p""q""r""s""t""u""v""w""x""y""z" );
        
        
    $random $letrand(025) ] . $letrand(025) ] . $letrand(025) ] . $letrand(025) ] . rand(09) . rand(09) . '-'$letrand(025) ] . $letrand(025) ] . $letrand(025) ] . $letrand(025) ] . rand(09) . rand(09);
        
        
    $random strtoupper$random );
        
        
    $query mysql_query"SELECT `column` FROM `database` WHERE `column` = '"$random ."'" );
        
    $num mysql_num_rows$query );
        
        if( 
    $num )
        {
        
            
    $random generate();
            
        }
        else
        {
        
            return 
    $random;
            
        }
        

    So in your code to get a unique code you would just do like $randomString = generate() and then the fuction would keep cycling until it gets a unique variable. (The above code should work).
    Last edited by Invent; 07-08-2008 at 06:58 PM.

  3. #3
    Join Date
    Feb 2006
    Location
    Scotland
    Posts
    2,087
    Tokens
    138

    Latest Awards:

    Default

    Oh, it has that lol!

    Thanks, +REP

  4. #4
    Join Date
    May 2005
    Location
    San Francisco, CA
    Posts
    7,160
    Tokens
    2,331

    Latest Awards:

    Default

    That's what my first code does, lol.
    PHP Code:
     <?php

    $let 
    = array( "a""b""c""d""e""f""g""h""i""j""k""l""m""n""o""p""q""r""s""t""u""v""w""x""y""z" );

    $random $letrand(025) ] . $letrand(025) ] . $letrand(025) ] . $letrand(025) ] . rand(09) . rand(09) . '-'$letrand(025) ] . $letrand(025) ] . $letrand(025) ] . $letrand(025) ] . rand(09) . rand(09);

    $random strtoupper$random );

    echo 
    $random;

    ?>

Posting Permissions

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