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

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

For generating a unique code you will need to check if it already exists, and if it does regenerate.
If you don't want the loop you could create this as an iterative method.

PHP Code:
public function generate_code() {
 
   $code random_string('alnum'16);
 
   $this->db->where('guest_code'$code);
 
   $check $this->db->count_all_results('guests');
 
   if $check >= ) {
 
      return $this->generate_code();
 
   }
 
   return $code;

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 - 10-30-2015, 09:31 AM



Theme © iAndrew 2016 - Forum software by © MyBB