Re: 4 Digit ID with Leading Zeros

From: Date: Thu, 15 Dec 2005 15:10:59 +0000
Subject: Re: 4 Digit ID with Leading Zeros
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-227469@lists.php.net to get a copy of this message
On 12/15/05, Rahul S. Johari <rjohari@nycap.rr.com> wrote: > Ave, > > 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. Salve, (a) It won't make a blind bit of difference to MySQL whether you have leading zeros or not. It gets stored the same way. (b) If you want to *display* the ID with 4 digits or generate a filename in that format, use sprintf('%04d', $ID); -robin

« previous php.general (#227469) next »