Assigning a file number
| From: | John Taylor-Johnston | Date: | Sun, 03 Nov 2013 06:04:15 +0000 |
| Subject: | Assigning a file number | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-322414@lists.php.net to get a copy of this message | ||
I need to assign a unique file number
50-20131103-0001
Ussers work in secteur 50
Today is 20131101
The first file number possible today is 0001 (of probably no more than 9999.
How should I build this?
Should I
create a varchar in MySQL and stock it all in one field?
or
have three separate fields?
secteur: '50' (INT) default=50
date: (DATESTAMP)
filenumber 0001 (INT)
Then here comes the PHP question?
When a user opens up my php page, my code will automatically assign $filenumber sequentially.
So how do I check if $filenumber = 0001 exists already? Using a while or if seems like a lot of work. Swatting a fly with a baseball bat.
There must be an easier trick, maybe a MySQL function to says if 0001 is taken, check and see if 0002 is available ++ until one is free. Then INSERT it so my user can enter his data.
John