Welcome Guest, Not a member yet? Register   Sign In
Does this small piece of code seem ok?
#1

(This post was last modified: 10-30-2015, 09:04 AM by PaulD.)

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.
Reply


Messages In This Thread
Does this small piece of code seem ok? - by PaulD - 10-30-2015, 09:02 AM



Theme © iAndrew 2016 - Forum software by © MyBB