Hi...
Hopefully I can explain this well enough.
I'm working with a website that INSERTs new users with two identifiers... a userID (that's unique and permanent), and a userCODE (which can be changed). Currently when a new user signs up, the code assigns the next available userCODE to the new user from the last user who signed up. For example, if Joe Bloe signs up and is assigned userCODE 1123, when Fred Joe signs up a day later, he'll get userCODE 1124. The code I'm using to do this is listed below :
// Create Next User Code Script //
$user = "SELECT MAX(user_code) FROM user";
$user_result = @mysql_query($user, $connect) or die(mysql_error());
while ($user_row = mysql_fetch_array($user_result)) {
$ucode = $pcd_row['MAX(user_code)'];
$user_code = ($ucode + 1);
}
The problem is that, when users are deleted from inactivity, it frees up userCODEs for use again. For example, if Joe Bloe is deleted, then userCODE 1123 would be available for use... but with the code above, since Fred Joe is active and his userCODE is 1124, the next userCODE that will be assigned will be 1125, not 1123.
So what I need to do is figure out how to run either a loop or some such that allows the script above to loop through the userCODEs in the user table and assign the next available number... rather than the MAX number. I'm not really sure how to do that... I haven't played with loops a lot.
Can anyone give me any ideas?
Thanks in advance...