Generating code and checking against DB
I'm working on a db entry script that generates a 6-character code, checks to see if that code is in the db already, and re-generates the code if it's found.
This is probably pretty simple, and I think I have a working solution but I'd like to have some other eyes look at it.
As you can see, I hard coded a value into the $code var that I know is in the DB. Does this seem like the most efficient way, or am I missing out on a better way?
//$code = strtoupper(genCode(6));
$code = 'ABCDEF';
$query = "SELECT clientcode ";
$query .= "FROM clients ";
$rows = $dbh->query($query);
foreach($rows as $row)
$code = strtoupper(genCode(6));
Thanks for any advice.