Skip to content

Instantly share code, notes, and snippets.

@tristar500
Created May 19, 2012 19:47
Show Gist options
  • Save tristar500/2732168 to your computer and use it in GitHub Desktop.
Save tristar500/2732168 to your computer and use it in GitHub Desktop.
Create 6 char uniquie ID
private function generateUniqueID()
{
// creates a unique 6 position alphanumeric client id
// if the client id is already in the clients table then call this function again
// otherwise return the client id
//
$newCode = strtoupper(substr(md5(uniqid(rand(), true)),0,6)); // creates a 6 digit token
if($this->job_model->isIDinUse($newCode)){
// that code exists already so try again
$this->generateUniqueID();
}else{
return $newCode;
}
}
function isIDinUse($newID)
{
$this->db->where('jobid', $newID);
$this->db->limit(1);
$query = $this->db->get('jobs');
$count = $query->num_rows();
if($count > 1)
{
return TRUE;
}
else
{
return FALSE;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment