Er, your earlier version(s) of the code was much closer. Try this:
function productCode($maxCode, $database_trustinme, $trustinme){
//Creates possible's variables to be used with the product code.
$codepossible = array("A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9");
$code_max = count($codepossible);
$productCode = array();
mysql_select_db($database_trustinme, $trustinme);
while(TRUE) {
for($i=0; $i < $maxCode; $i++){
$prod = rand(0, $code_max);
$productCode[$i] = $codepossible[$prod];
}
$productCode = implode(",", $productCode);
$selectSQL = "SELECT 1 FROM category WHERE productCode = '$productCode' LIMIT 1";
$Result1 = mysql_query($selectSQL, $trustinme) or die(mysql_error());
if(mysql_num_rows($Result1) == 0){
break;
}
}
session_start();
$_SESSION["productCode"] = $productCode;
}
I saw that you're using a comma in the implode() statement... is this really what you want? Product codes such as "A,5,C,3,3,W" etc. ? If not, use an empty string as the "glue" in the implode() statement.
EDIT: Also, to save some typing (and some space), you could shorten your $codepossible line to:
$codepossible = array_merge(range('A', 'Z'), range(0, 9));