Re: Unique ID system - need help/ideas
| From: | trlists at clayst dot com | Date: | Thu, 11 Mar 2004 04:32:28 +0000 |
| Subject: | Re: Unique ID system - need help/ideas | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-180098@lists.php.net to get a copy of this message | ||
On 10 Mar 2004 J J wrote:
> My problem is how do I recreate this in PHP to make
> sure any newly added records follow this same unique
> ID?
I haven't played much with these functions but I think for MySQL you'd
want something like this, for the state "XX" (excuse the wrapped
lines):
if ($result =
mysql_query("select max(id) from table where left(id, 2) = 'XX'")) {
$row = mysql_fetch_row($result);
$newid = strpad($row[0] + 1, 5, "0", STR_PAD_LEFT);
mysql_query("insert into table set id = 'XX'" . $newid);
$newrecnum = mysql_insert_id();
}
That is crude and uuntested, needs some error checking and most likely
table locking, but it's one possibility for a base.
--
Tom