Re: [PHP] 4 Digit ID with Leading Zeros

2005-12-16 Thread Curt Zirzow

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  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
1, 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

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



Re: [PHP] 4 Digit ID with Leading Zeros

2005-12-15 Thread Rahul S. Johari

Ave,

I did actually think about a periodic reset, as I do something like that for
one other application, different issue.

Thanks.


On 12/15/05 1:24 PM, "[EMAIL PROTECTED]"
<[EMAIL PROTECTED]> wrote:

> If it's really a temporary table, then you can probably reset the auto
> increment counter periodically so you'll never hit .
> 
> If it doesn't have to be 4 digits, that you just want it padded out with
> zeros, you can have the numbers in the databse be 1, 2, 3, 4 (regular, no
> padding) and just use PHP to pad the numbers for display purposes too.
> 
> Just some random thoughts.
> 
> -TG
> 
> = = = Original message = = =
> 
> Ave,
> 
> Now that is an interesting perception. I didn't think about that. Well I can
> always change it to five or six. Let me re-assess this with the concerned
> person in the department and see what the scenario is like. I'll have to
> check the fluency of incoming data and expectancy of reaching the 10,000th
> mark.
> 
> Thanks a bunch.
> 
> 
> 
> On 12/15/05 12:38 PM, "Jim Moseby" <[EMAIL PROTECTED]> wrote:
>  
>> Yes, but as I understand it, MySQL will continue to increment as new
>> records are added, so it would be possible that you have only one record
>> in the table, but not be able to add another because of the 4 digit
>> restriction.  If this is the case, you will only be able to have 10,000
>> ADDs, not 10,000 records.  Just something to be aware of.
>> 
>> JM
> 
> Rahul S. Johari
> Coordinator, Internet & Administration
> Informed Marketing Services Inc.
> 251 River Street
> Troy, NY 12180
> 
> Tel: (518) 266-0909 x154
> Fax: (518) 266-0909
> Email: [EMAIL PROTECTED]
> http://www.informed-sources.com
> 
> 
> ___
> Sent by ePrompter, the premier email notification software.
> Free download at http://www.ePrompter.com.

Rahul S. Johari
Coordinator, Internet & Administration
Informed Marketing Services Inc.
251 River Street
Troy, NY 12180

Tel: (518) 266-0909 x154
Fax: (518) 266-0909
Email: [EMAIL PROTECTED]
http://www.informed-sources.com

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



Re: [PHP] 4 Digit ID with Leading Zeros

2005-12-15 Thread tg-php
If it's really a temporary table, then you can probably reset the auto 
increment counter periodically so you'll never hit .

If it doesn't have to be 4 digits, that you just want it padded out with zeros, 
you can have the numbers in the databse be 1, 2, 3, 4 (regular, no padding) and 
just use PHP to pad the numbers for display purposes too.

Just some random thoughts.

-TG

= = = Original message = = =

Ave,

Now that is an interesting perception. I didn't think about that. Well I can
always change it to five or six. Let me re-assess this with the concerned
person in the department and see what the scenario is like. I'll have to
check the fluency of incoming data and expectancy of reaching the 10,000th
mark.

Thanks a bunch.



On 12/15/05 12:38 PM, "Jim Moseby" <[EMAIL PROTECTED]> wrote:
 
> Yes, but as I understand it, MySQL will continue to increment as new
> records are added, so it would be possible that you have only one record
> in the table, but not be able to add another because of the 4 digit
> restriction.  If this is the case, you will only be able to have 10,000
> ADDs, not 10,000 records.  Just something to be aware of.
> 
> JM

Rahul S. Johari
Coordinator, Internet & Administration
Informed Marketing Services Inc.
251 River Street
Troy, NY 12180

Tel: (518) 266-0909 x154
Fax: (518) 266-0909
Email: [EMAIL PROTECTED]
http://www.informed-sources.com


___
Sent by ePrompter, the premier email notification software.
Free download at http://www.ePrompter.com.

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



Re: [PHP] 4 Digit ID with Leading Zeros

2005-12-15 Thread Rahul S. Johari
Ave,

Now that is an interesting perception. I didn't think about that. Well I can
always change it to five or six. Let me re-assess this with the concerned
person in the department and see what the scenario is like. I'll have to
check the fluency of incoming data and expectancy of reaching the 10,000th
mark.

Thanks a bunch.



On 12/15/05 12:38 PM, "Jim Moseby" <[EMAIL PROTECTED]> wrote:
 
> Yes, but as I understand it, MySQL will continue to increment as new
> records are added, so it would be possible that you have only one record
> in the table, but not be able to add another because of the 4 digit
> restriction.  If this is the case, you will only be able to have 10,000
> ADDs, not 10,000 records.  Just something to be aware of.
> 
> JM

Rahul S. Johari
Coordinator, Internet & Administration
Informed Marketing Services Inc.
251 River Street
Troy, NY 12180

Tel: (518) 266-0909 x154
Fax: (518) 266-0909
Email: [EMAIL PROTECTED]
http://www.informed-sources.com

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



Re: [PHP] 4 Digit ID with Leading Zeros

2005-12-15 Thread Jim Moseby

Rahul S. Johari wrote:


Ave,

Primarily the application is for recycling some data. Things will be added
by a client, shortly processed thereafter in-house, and removed. We won't be
reaching the 10,000 records for this application.

Thanks.

 

Yes, but as I understand it, MySQL will continue to increment as new 
records are added, so it would be possible that you have only one record 
in the table, but not be able to add another because of the 4 digit 
restriction.  If this is the case, you will only be able to have 10,000 
ADDs, not 10,000 records.  Just something to be aware of.


JM

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



Re: [PHP] 4 Digit ID with Leading Zeros

2005-12-15 Thread Rahul S. Johari
Ave,

Yes phpMyAdmin does but I'm sure many other don't. I'll keep this in mind.
Thanks.


On 12/15/05 11:01 AM, "John Hinton" <[EMAIL PROTECTED]> wrote:

> Rahul S. Johari wrote:
> 
>> Ave,
>> 
>> I'm looking into the ZEROFILL option now. Didn't know about it before but it
>> looks promising and probably is my solution. I'll get back.
>> 
>> Thanks a ton!
>> 
>> On 12/15/05 10:24 AM, "Jim Moseby" <[EMAIL PROTECTED]> wrote:
>> 
>>  
>> 
> Zerofill in mysql will do it. But, many mysql 'clients' don't 'display'
> the zeros. As best that I remember, phpMyAdmin does show the zeros, so
> be careful as what you 'see' might not really be what you 'get'. Seems
> like there are issues with the viewing of this in Excel as well..
> Friggin programs that think they are smarter that people
> 
> Anyway, that'll do the mysql side of it for you.
> 
> John Hinton

Rahul S. Johari
Coordinator, Internet & Administration
Informed Marketing Services Inc.
251 River Street
Troy, NY 12180

Tel: (518) 266-0909 x154
Fax: (518) 266-0909
Email: [EMAIL PROTECTED]
http://www.informed-sources.com

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



Re: [PHP] 4 Digit ID with Leading Zeros

2005-12-15 Thread Rahul S. Johari
Ave,

Primarily the application is for recycling some data. Things will be added
by a client, shortly processed thereafter in-house, and removed. We won't be
reaching the 10,000 records for this application.

Thanks.

On 12/15/05 11:00 AM, "Jim Moseby" <[EMAIL PROTECTED]> wrote:

>> 
>> I'm looking into the ZEROFILL option now. Didn't know about
>> it before but it
>> looks promising and probably is my solution. I'll get back.
> 
> Obviously, with a 4 digit id, you will only be able to store 10,000 records.
> If I recall correctly, MySQL auto-increment fields will not reuse id's when
> they are deleted.  So, you will need to take that into consideration when
> (if) you reach the 9,999th record.
> 
> JM

Rahul S. Johari
Coordinator, Internet & Administration
Informed Marketing Services Inc.
251 River Street
Troy, NY 12180

Tel: (518) 266-0909 x154
Fax: (518) 266-0909
Email: [EMAIL PROTECTED]
http://www.informed-sources.com

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



Re: [PHP] 4 Digit ID with Leading Zeros

2005-12-15 Thread Rahul S. Johari

Ave,

That Worked!!
That was the perfect solution. Everything is working just the way I wanted
it to work now. I'm using ZEROFILL in my mySQL table and pulling the ID to
generate the filename.

Thanks a TON!

On 12/15/05 10:17 AM, "David Grant" <[EMAIL PROTECTED]> wrote:

> Rahul,
> 
> Rahul S. Johari wrote:
>> 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
> 
> Adding ZEROFILL to that definition might be what you're after.
> 
> Cheers,
> 
> David

Rahul S. Johari
Coordinator, Internet & Administration
Informed Marketing Services Inc.
251 River Street
Troy, NY 12180

Tel: (518) 266-0909 x154
Fax: (518) 266-0909
Email: [EMAIL PROTECTED]
http://www.informed-sources.com

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



Re: [PHP] 4 Digit ID with Leading Zeros

2005-12-15 Thread Anas Mughal
The suggestions made are all great.

However, I have a problem understanding the requirement of having the Id in
the database matchup with the filename. (You could always append the when
binding the database Id with the filename.)

Please elaborate on your requirements.
Thanks.



On 12/15/05, Jim Moseby <[EMAIL PROTECTED]> wrote:
>
> >
> > I'm looking into the ZEROFILL option now. Didn't know about
> > it before but it
> > looks promising and probably is my solution. I'll get back.
>
> Obviously, with a 4 digit id, you will only be able to store 10,000
> records.
> If I recall correctly, MySQL auto-increment fields will not reuse id's
> when
> they are deleted.  So, you will need to take that into consideration when
> (if) you reach the 9,999th record.
>
> JM
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


--
Anas Mughal


RE: [PHP] 4 Digit ID with Leading Zeros

2005-12-15 Thread Jim Moseby
> 
> I'm looking into the ZEROFILL option now. Didn't know about 
> it before but it
> looks promising and probably is my solution. I'll get back.

Obviously, with a 4 digit id, you will only be able to store 10,000 records.
If I recall correctly, MySQL auto-increment fields will not reuse id's when
they are deleted.  So, you will need to take that into consideration when
(if) you reach the 9,999th record. 

JM

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



Re: [PHP] 4 Digit ID with Leading Zeros

2005-12-15 Thread John Hinton

Rahul S. Johari wrote:


Ave,

I'm looking into the ZEROFILL option now. Didn't know about it before but it
looks promising and probably is my solution. I'll get back.

Thanks a ton!

On 12/15/05 10:24 AM, "Jim Moseby" <[EMAIL PROTECTED]> wrote:

 

Zerofill in mysql will do it. But, many mysql 'clients' don't 'display' 
the zeros. As best that I remember, phpMyAdmin does show the zeros, so 
be careful as what you 'see' might not really be what you 'get'. Seems 
like there are issues with the viewing of this in Excel as well.. 
Friggin programs that think they are smarter that people


Anyway, that'll do the mysql side of it for you.

John Hinton

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



Re: [PHP] 4 Digit ID with Leading Zeros

2005-12-15 Thread Rahul S. Johari

Ave,

I'm looking into the ZEROFILL option now. Didn't know about it before but it
looks promising and probably is my solution. I'll get back.

Thanks a ton!

On 12/15/05 10:24 AM, "Jim Moseby" <[EMAIL PROTECTED]> wrote:

>> 
>> What I would have preferred to have is make both the ID in
>> mySQL table and
>> the filename have the leading zeros. But I'm not sure if
>> that's possible.
> 
> 
> Then, take the suggestion of another respondent to this topic, and have a
> look at MySQL's "ZEROFILL" option.  I'm not sure if you can use it with an
> auto-increment field, but that's my best guess.
> 
> JM

Rahul S. Johari
Coordinator, Internet & Administration
Informed Marketing Services Inc.
251 River Street
Troy, NY 12180

Tel: (518) 266-0909 x154
Fax: (518) 266-0909
Email: [EMAIL PROTECTED]
http://www.informed-sources.com

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



RE: [PHP] 4 Digit ID with Leading Zeros

2005-12-15 Thread Jim Moseby
> 
> What I would have preferred to have is make both the ID in 
> mySQL table and
> the filename have the leading zeros. But I'm not sure if 
> that's possible.


Then, take the suggestion of another respondent to this topic, and have a
look at MySQL's "ZEROFILL" option.  I'm not sure if you can use it with an
auto-increment field, but that's my best guess.

JM

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



Re: [PHP] 4 Digit ID with Leading Zeros

2005-12-15 Thread Rahul S. Johari

Ave,

I think this will work for me.
Here's what I'm gonna do...

When the form is submitted:
First, add the records to the mySQL table. An ID will be automatically
generated.

Then, call the ID from the mySQL table, using your code, add the leading
Zeros to it, and generate the CSV file with that new ID as the filename.

The only issue that I still have is... The file name will be "0001.csv",
while in the mySQL table, the ID for that record who's csv file has been
generated, will be "1".

What I would have preferred to have is make both the ID in mySQL table and
the filename have the leading zeros. But I'm not sure if that's possible.

Thanks.

On 12/15/05 10:10 AM, "Jim Moseby" <[EMAIL PROTECTED]> wrote:

>> 
>> I¹m trying to figure out how to do this but am not sure.
>> Any help appreciated.
>> 
> 
> I'm not sure of what you are asking, but I'll assume that because you posted
> the to the PHP list, that you are asking how to take a MySQL autoincrement
> number and add leading zeros to it.
> 
> Try this: 
> 
> $row=mysql_fetch_array($result);
> $four_digit_id=str_pad($row['id'], 4, "0", STR_PAD_LEFT);
> 
> JM

Rahul S. Johari
Coordinator, Internet & Administration
Informed Marketing Services Inc.
251 River Street
Troy, NY 12180

Tel: (518) 266-0909 x154
Fax: (518) 266-0909
Email: [EMAIL PROTECTED]
http://www.informed-sources.com

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



Re: [PHP] 4 Digit ID with Leading Zeros

2005-12-15 Thread David Grant
Rahul,

Rahul S. Johari wrote:
> 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

Adding ZEROFILL to that definition might be what you're after.

Cheers,

David
-- 
David Grant
http://www.grant.org.uk/

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



RE: [PHP] 4 Digit ID with Leading Zeros

2005-12-15 Thread Jim Moseby
> 
> I¹m trying to figure out how to do this but am not sure.
> Any help appreciated.
> 

I'm not sure of what you are asking, but I'll assume that because you posted
the to the PHP list, that you are asking how to take a MySQL autoincrement
number and add leading zeros to it.

Try this: 

$row=mysql_fetch_array($result);
$four_digit_id=str_pad($row['id'], 4, "0", STR_PAD_LEFT);

JM

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



Re: [PHP] 4 Digit ID with Leading Zeros

2005-12-15 Thread Robin Vickery
On 12/15/05, Rahul S. Johari <[EMAIL PROTECTED]> 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