Posted By

amyb on 02/04/11


Tagged


Versions (?)

Generate a random reference code and check it's unique


 / Published in: PHP
 

  1. $unique = FALSE;
  2.  
  3. while ($unique == FALSE){
  4.  
  5. $ref = md5(date('r', time()) . rand(0,100));
  6.  
  7. $check_ref = mysql_query("SELECT ref FROM table_name WHERE ref = '$ref'");
  8.  
  9. if(mysql_num_rows($check_ref)==0){
  10.  
  11. $unique = TRUE;
  12.  
  13. }
  14.  
  15. }

Report this snippet  

You need to login to post a comment.