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.
Ajax Error since Upgrading to 3.5
Ever since upgrading my site to .NET 3.5 (I needed LINQ), I've been getting this annoying error on one of my pages:
Async WSAConnect failed on XP with error code = 2 ("File not found")
Hi all,
Database connection failure
Hello All,
OPINIONS WANTED
This is my login page code, and I want your opinion on it please! Code: // Login ~ CHECKS THE (USERNAME/PASSWORD) ENTERED BY THE USER THEN EITHER GRANTS ACCESS OR DENIEDS ACCESS case
php mysql query from input textbox
Hi,I have a text box, in that i have given the mysql query. I can able to get the query in variable. But after submit button i want to get data to be printed on a same page. But how can i print the
Need help: how to catch acess of undefined class properties
Hello. I am learning OO with PHP and have hit a problem.Some code runs as perfectly valid code, where i would like PHP to issue a warning / error.I guess this is because of the loose typing of PHP,
Save remote XML to local website folder
Hi, I hope you can help me out. I would like to be able to pull an XML file from another site and then store it in a local folder on my site. That way, I would only need to pull the xml file once in
How to file_get_contents when login required?
Hello!I am trying to read data from a page that you have to be logged into to view, I am trying to use file_get_contents to do this, I have read that I need to use cURL, Is that true?Also, as Another
extract content from a website
i have written a code that will grab the content from the index page..i would like to know how can i leech completely thru the site (index,contact, news pages) and grab specific content only like
EXplanation help
Hey all,I am still fairly new to PHP programming and I am trying to put together a page where you select search terms from a drop down menu and it keeps the menu at your search choice in the menu