|
Posted by Curt Zirzow on 12/16/05 10:43
I got lost in the mix of threads, so here is my input on the
situation.
On Thu, Dec 15, 2005 at 09:53:46AM -0500, Rahul S. Johari wrote:
> I want to assign a 4 Digit ID with leading zeros to each record added using
> a form I have created.
>
> The PHP scripts does two things:
> (a) It adds the data to a mySQL table
> (b) it generates a CSV file with the data
>
> The 4 Digit ID (beginning from 0001) will be used in two places:
> (a) It will be the ID for the record in the mySQL table, instead of the
> usual ID that we create in mySQL. It will be a Primary Key, Not Null,
> Auto_Increment
> (b) It will also be the filename for the CSV file.
>
> So basically it has to match the record adding in the mySQL table and the
> filename for the CSV.
There seems to be a design flaw with this. As mentioned, well you
dont expect to have over 9999 entries, you simply cant rely on the
auto_increment to deal with this as it easily can get over the
number with only one record. If 4 chars is an issue then i would
avoid using the auto_increment as the Primary key.
As Far as making sure that the file is written as the current
specifications call for the leading zero's is a virtual concept.
Consider:
The query to get the record with and ID of 0001:
select * from table where id = 0001
This since 0001 is the same as 1 there really isn't any meaning
behind the textual 0001.
A result from an auto_increment that is just '1' can easily be
formated to output as 0001:
$file = sprintf('%04s', 1);
At this point the only limiting factor is the output of the
filename.
As far as not expecting the auto_increment value never reaching
10000, when I was 10 years old I thought anyone that was 30 was an
old person.
HTH,
Curt.
--
cat .signature: No such file or directory
Navigation:
[Reply to this message]
|