1,105,344 Community Members

Auto Generate key

Member Avatar
Light Poster
32 posts since Jan 2013
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
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

Member Avatar
Posting Virtuoso
1,576 posts since Jan 2011
Reputation Points: 220 [?]
Q&As Helped to Solve: 218 [?]
Skill Endorsements: 21 [?]

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 three months: Start a new discussion instead
Start New Discussion
Tags Related to this Article