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

(11-04-2015, 10:50 AM)mwhitney Wrote: Especially compared to all of the discussion about randomness, this is a minor item, but I would generally forego the extra variable and do something like this:

PHP Code:
$check 0;
while (
$check === 0) {
    
$code get_random_string();
    
$check $this->db->where('guest_code'$code)->count_all_results('guests');


or

PHP Code:
do {
    
$code get_random_string();
    
$check $this->db->where('guest_code'$code)->count_all_results('guests');
} while (
$check === 0); 

It has been awhile but I just had to reply on this.

Shouldn't it be

PHP Code:
while( $check === 

Because no match means $check remains 0 and the cycle is run again right? But we only want the cycle to rerun if a match was found setting $check = 1;
Reply


Messages In This Thread
Does this small piece of code seem ok? - by PaulD - 10-30-2015, 09:02 AM
RE: Does this small piece of code seem ok? - by Martin7483 - 06-23-2017, 01:21 AM



Theme © iAndrew 2016 - Forum software by © MyBB