I can accomplish the task with a while loop in php, but haven’t ever used a while loop in mysql (thought this is a good opportunity) . I’ve read the reference http://dev.mysql.com/doc/refman/5.0/en/while-statement.html ,but don’t understand how to get the results of the while loop into the field in a UPDATE query.
That sort of calculation would be far more efficiently done outside of the database. Validating the checkdigit would be something you’d do as part of the validation you do long before the field ever gets anywhere near the code that adds it into the database in the first place. Once the data is in the database the checkdigit should always be valid as invalid ones should never be inserted to start with. Sanitising the value after you retrieve it if you want to make sure no one has tampered with the database content would also be best done after you get the field back out of the database.
You should use each language for what it is best at and PHP is far more efficient at those sort of calculations than any database would be.