PSuedo code
Get unix timestamp ie 1115501044
While(ID does exist in DB)
{
Increment ID by 1
}
ID = newvalue;
but how would i do this in php..
Thanks in advance
Any database system (e.g. MySQL) will automatically do this for you if
you select a field as AUTOINCREMENT.
--
Oli
$testid='1115571604';
$unique_result='1';
while($unique_result)
{
$rs= mysql_query("Select ID from Items where ID =
'$testid'");
if (mysql_fetch_array($rs))
{
$testid++;
}
else $unique_result = '0';
}
echo "$testid";
but how can i lock it so no one straight after can grab the same value
during the time it takes to execute the rest of the code following this.
"Oli Filth" <ca...@olifilth.co.uk> wrote in message
news:Nvrfe.11047$996....@newsfe6-gui.ntli.net...
Why do you need it to correspond *uniquely* to the creation time? Like I
said previously, if you need a unique ID, then use the autoincrement
feature. If you need a timestamp, then store the timestamp as well. It's
considered bad design practice to have one database field serving two
purposes, not least because it involves kludges like this.
What's more, by changing the ID field of records on UPDATEs, you're
destroying the relational aspect of the database, because you can't use
this ID value as a foreign key in other tables (i.e. you can't identify
this row from other tables).
But if you still want to do this, then use a table lock, i.e.
LOCK TABLE table_name WRITE;
...
UNLOCK TABLES;
P.S. It would be much more efficient if you treat the ID value in your
example above as an integer rather than a string.
--
Oli
"Oli Filth" <ca...@olifilth.co.uk> wrote in message
news:Ewsfe.22261$YF5....@newsfe5-win.ntli.net...
http://ham.jen-gen.com
"roger" <pag...@ntlworld.com> wrote in message
news:T_vfe.26191$5A3....@newsfe4-win.ntli.net...