Re: Incremental Date Based ID

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



At 08:46 PM 3/7/2006, Kevin Murphy wrote:

I'm trying to set up an ID field that works like this for news
articles that are posted to a website.

2006-03-05a
2006-03-05b

I know how to generate the date, and I am pretty sure I can generate
the letter code based on counting the number of rows and then
assigning the next letter (we will never have more than 26 in a
day... usually its closer to 1 or 2 per day).

The problem is if there has been something deleted.

2006-03-05a
2006-03-05c

If I then Count the rows with this date I get an answer of 2, and so
the next letter should be "c" but there already is a "c" because "b"
got deleted.

So, is there any way of generating this style ID number automatically?

--
Kevin Murphy
Webmaster - Information and Marketing Services
Western Nevada Community College
www.wncc.edu
(775) 445-3326


Why make it so HARD??????
Having gone that far, just timestamp your id. Not a timestamp in the sense of it being triggered whenever a record was changed, but the time it was created.

Better yet - use your publish date and assign a sequence number to the article. Doesn't matter what the number is, but you can then use it to roughly - or accurately - sequence articles for publication. If articles have same sequence number they'll appear in whatever order they were added to the database.

For a count of the articles, just count(pub_date).

And yes, if you insist, you can generate the number automatically. Just establish a table for id values. It has two fields, table_name and id_value. Write a function to grab the current id_value, then increment and store it. Note grab first, then increment and store. I still think this is much more work than you need.

Regards - Miles Thompson

--
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.1.375 / Virus Database: 268.2.0/275 - Release Date: 3/6/2006

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux