Hi etully, I hope you are still logging on to this site. Over the last few weeks I have had other things to do but I'm back into this project. I have studied your code and rather that search every possible numeral I think it would be much simpler to process the search in the following method, that is if it is possible. I am only guessing so there will be no accuracy in this code but you should be able to follow my thinking.
// Assume that the previous page has a form that asks the customer
// to enter their preferred username and is passed in as "user"
$user = $_REQUEST['user'];
// Query the database for any usernames that start with that value and widcard number
$query = "SELECT username FROM users WHERE username REGEXP '$user[0-9*]'";
$result = mysql_query($query);
if (!$result($user,$username)) {
$user = "$user,1";
$q = "INSERT INTO users VALUES ('$username')";
}
if ($result($user[0-9*])) {
mysql_bottom
mysql_findup REGEXP '[0-9*]'
$i=mysql_copy
$i++;
$user = "$user,$i";
$q = "INSERT INTO users VALUES ('$username')";
}
Regards, David.