Hey everyone.... I have a project where I add new records into MYSQL. Along with the standard autoincrement unique id, I also would like to have a 6 digit alphanumeric code that is associated with each record (which would also need to be unique. I have the script to create the unique id: [code]$token = substr(md5(uniqid(rand(), true)),0,6); // creates a 6 digit token[/code] I would need to query the DB to ensure that the number hasn't been used already. Sure its like a billion to one, but its the right thing to do. My question is. If the value is taken, can I call the same function again from within itself, or is that bad coding? [code] function generateUniqueID () { $token = substr(md5(uniqid(rand(), true)),0,6); // creates a 6 digit token $query = "SELECT count(*) FROM table WHERE code = $token"; $result = mysql_query($query, $connection) or die(mysql_error()); $numResults = mysql_num_rows($result); if (!$numResults) { generateUniqueID(); } } [/code] Also, if your wondering why I dont go with the entire 32 character md5 string. Its because the code needs to be short enough for people to be able to enter it easily. Any guidance would be appreciated.