This works if there are other account numbers in the table, ie if TES001 exists the $newaccount value is TEC002.
However, i tested the domain zzr.com and it returned ZZR000, it needs to be ZZR001. Any ideas?
Here is the code...
// Calculate the Account Number
db_connect();
$acct_prefix = strtoupper( substr ( "$domain_name",0,3 ) );
$sql = "SELECT MAX(account_id) as lastused from accounts WHERE account_id LIKE '$acct_prefix%' ";
$result = mysql_query( $sql );
if ( mysql_num_rows ( $result ) == 0 ) {
$newaccount = $acct_prefix.'001';
}
else {
$row = mysql_fetch_assoc ( $result );
$num = substr($row['lastused'], 3);
$num++;
$newaccount = sprintf ( '%s%03d', $acct_prefix, $num );
}
mysql_close();
echo $newaccount;
exit;