Hi guys n gals,
I have a requirement to generate 250,000 unique codes...
These codes are for a tracking service and will be stored in the database (table field has a unique index).
Now I am working on the assumption this must work on the command line as the script will take a long time to complete... here is the salient pat of my code...
Code: <?php
...
function appendToCode( &$val , $key , $append )
{
$val = $val . $append;
}
$chars = "ABCDEFGHJKLMNPQRSTUVWXYZ";
$charend = strlen ( $chars );
$date = date ( 'md' );
$month = $date[0].$date[1];
$year = $date[2].$date[3];
$datecode = $chars[$month] . $chars[$year[0]] . $chars[$year[1]];
$codes = array();
$no_codes = isset( $_GET['no_codes'] ) ? $_GET['no_codes'] : 250000;
$codecount = 0;
do
{
for ( $j = $codecount ; $j < $no_codes ; $j++ )
{
$trackcode = NULL;
for ( $i = 0 ; $i < 7 ; $i++ )
{
$trackcode .= $chars[rand( 0 , $charend - 1 )];
echo ( time() - $start ) . PHP_EOL;
}
$codes[] = $trackcode . $date;
}
//$t = count($codes);
//echo 'Codes Generated: ' . $t . PHP_EOL;
//echo 'Last Code: ' . $codes[--$t] . PHP_EOL;
$codes = array_unique( $codes );
$codecount = count ( $codes );
//echo 'Unique Codes: ' . $codecount . PHP_EOL;
// the following statement prevents infinite loop in dev mode...
if (
(time() - $start) > 150
)
{
break;
}
} while ( $codecount < ($no_codes) - 1 );
...
The last characters of the code relate to the date - as these codes will only be developed every now and then - not a frequent occurrence and will allow a check on the database to see if codes ending in that 3 character string exist...
What I am asking is, is there a more efficient method of performing this operation.
Any tips would be most welcome.
dropdown box help - open php files to textarea
Hi, I am using tinymce to edit content located in several php files. The code I attached works but is missing some functionality and I am very new at php so I need some help or advise please.What I
Beginners syntax and loop questions - help please!
Hi everyone,I have some problems with php code. I'm currently in the middle of learning php, but these problems have got me stuck fast. But also have a question regarding looping that i'll ask in the
Issue Parsing XML into table
Hello all,Im a bit new to php and new to phpfreaks. But thanks in advance for the help!Im parsing an xml feed into a table. The only problem is that one of the fields can not format properly in the
Unifying logins of two different scripts
I have two different game scripts which I want to embed on my own site. The problem is I don't want users to create 3 different accounts - one for main site and 2 other for games. I want them to just
Rounding a number queried from a database
I know that to display a rounded number you just do echo "round($number)";. But how would I convert the $number varible into a rounded number, so that when I say echo "$number";
Multidimensional array problems in $_POST
I'm having trouble with a three-dimensional $_POST array. It starts as a two-dimensional array on this side:Code: <html> <head>
Code clarification
Hi In the following code what could be the "search_print()" and where it could be placed.Couldn't find within the page or included pagesCode: [Select]<td align="right"
Help to integrate whois Domain Details to website
Hi, can i know is their any php script r methods to add domain details to my website.I mean when user wants to know the details about a particular domain they will type in a text box, so that we need
Help with captcha script needed
Hello, I am working on a script where reCAPTCHA or a similar form of CAPTCHA will be used, for the sake of this example I will talk about reCAPTCHA. I wanted to know how I could have the reCAPTCHA
Displaying image from database
Hi,I've got a site where that's got a database behind it. Currently it has loads of items in rows that all have different pictures. There is a field called "Image" that has the name of the