Hi,
I am not sure why but I am uncomfortable with this piece of code.
All I am doing after this loop is inserting the generated $code value (not for crypotgraphic purposes) into a unique column, in a later query. So to make sure the code is unique I am doing this:
PHP Code:
$loop = TRUE;
while($loop)
{
$code = random_string('alnum', 16);
$this->db->where('guest_code', $code);
$check = $this->db->count_all_results('guests');
if ($check == 0)
{
$loop = FALSE;
}
}
But I am uncomfortable with the loop though. Is this a sensible way to do this?
It is working and I have moved on for now but it is bugging me because of the potential for an infinite loop. Is this a bad thing to do or am I being silly.
Any advice would be welcomed,
Best wishes,
Paul.