Generate Serial From MYSQL

Discussion in 'PHP' started by Internal09, Jul 13, 2011.

  1. #1
    Hi, I need a script that would allow me to put serials in the MYSQL database and then when I visit the PHP script and user clicks generate it will generate a random serial from the MYSQL Database. Is this possible? Thanks.
     
    Internal09, Jul 13, 2011 IP
  2. BRUm

    BRUm Well-Known Member

    Messages:
    3,086
    Likes Received:
    61
    Best Answers:
    1
    Trophy Points:
    100
    #2
    Of course it's possible. Buy a book on PHP and SQL or come back with code that doesn't work.

    If you have some spare cash I'd be willing to create the script for you. I'm a programmer by trade.
     
    BRUm, Jul 14, 2011 IP
  3. coder0403

    coder0403 Peon

    Messages:
    44
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    You can try this script: blog.biernacki.ca/2007/03/php-serial-number-generator
     
    coder0403, Jul 14, 2011 IP
  4. spletnisistemi

    spletnisistemi Peon

    Messages:
    50
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    You can try this:

    $i = 0;
    while ($i < 50) {
    $random = "abcefghijklmnopqrstuvwxyz123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    $randCode = str_shuffle($random));

    echo $randCode;
    }
     
    spletnisistemi, Jul 15, 2011 IP
  5. BRUm

    BRUm Well-Known Member

    Messages:
    3,086
    Likes Received:
    61
    Best Answers:
    1
    Trophy Points:
    100
    #5
    While str_shuffle() can be used for this purpose, there is a possibility of creating duplicate strings. Extra precautions must therefore be made:

    
    
    <?php
    
        $str  = "a...Z"; // shorthand notation - fill this in with all allowable chars
        $codes = array();
        $code = null;
        $numCodes = 10;
    
        for($i = 0; $i < $numCodes; $i++)
        {
            do
            {
                $code = str_shuffle($str);
            }
            while(in_array($code, $codes));
            $codes[] = $code;
        }
    
        print_r($codes);
    
     ?>
    
    
    PHP:
     
    Last edited: Jul 15, 2011
    BRUm, Jul 15, 2011 IP