Nope because the function will recall its self, thus testing with the newly generated code value each time until it finally resolves out of the function by getting to the else. Actually what needs to happen is this instead because it will not initialize code properly
<?php
function make_code (){
$code = "";
$i = 0;
while($i <=10){
$code .= chr(rand(97,122));
$i++;
}
return $code;
}
function code_test(){
$code = make_code();
$q = "select from `table` where Code = '".$code."'";
$r = mysql_query($q) or die(mysql_error());
if(mysql_num_rows($r){
//We found a match lets re roll code
code_test();
}
else{
//valid unused code lets return out of the function
}
}
//Connect to your sql db
code_test();
?>
However the generator done by uniqid(); is not a bad choice, but if you want to control what goes in your code (Some people don't like the number 1 or the letter "I" or "L" because of possible confusion so they remove them from the random bank. I wrote a very basic code generator that only generates alpha characters you can redo it and make it generate all sorts of fun things