1.11M Members

Auto Generate key

function autogen()
     $qr="Select * from autogen where gid = 1";
     $we=mysql_query($qr)or die(mysql_error());
      $lw= ++$ln;
      return $lw;
$qry="Select * from leads";
$r=mysql_query($qry) or die(mysql_error());
$er="UPDATE autogen SET autoln='$newlead'WHERE gid =1";
$bn=mysql_query($er)or die(mysql_error());

This Code generates the key like LEA4545

but this code have some flaws same id could be inserted in table

although i have set in fuction in same found incre ent in it..

and the second flaw is this if i delete the keys ..then the new one created key must be from deleted keys


Let me repeat to see if I understood:

You want to generate unique keys yourself (IOW mysql autoincrement is not OK for your purpose). What is the format of the key and what are the rules for constructing the key?

then the new one created key must be from deleted keys

If this is the requirement then you have to keep the list of the deleted keys. If you keep it in a database table then just query for first available key.

This article has been dead for over six months: Start a new discussion instead
Start New Discussion
Tags Related to this Article