|
|
|
|
![]() ![]() |
Mar 16 2005, 12:27 AM
Post
#1
|
|
|
Premium Member Group: Members Posts: 208 Joined: 6-September 04 From: England Member No.: 315 |
Hi all, i am working on a Gallery commenting script for myself and i got stuck at a part of it. I would like each new comment added to an image to be a number as the text file name like 1, 2, 3. everytime they add a comment the next file name is incremented (+1) and so on for example; if there was a text file names '1' then the next would be named '2'.
I know how to create the file and the rest of it, but i would like to know how to do this. I should probably store the last file name somehow and then add 1 to it to create the next file but i do not know how. Thanks overture. |
|
|
|
Mar 16 2005, 01:11 AM
Post
#2
|
|
|
Absolute Newbie Group: Admin Posts: 888 Joined: 20-February 05 From: Indianapolis, Indiana, USA (Midwest) Member No.: 2,714 myCENTs:35.43 |
php has a built in ID function that generates an alphanumeric value based on microtime.
See Also This Topic Otherwise, if you really want 1, 2, 3, 4, 5, 6, 7, ... You'll need to create a count file with one line in it. The line will just be the current number of files saved. each time you save the comment file, you'll need to open the count fill, read the value, add 1 to the value, write the new value to the count fill and add the new value to the end of your filename. This would create something like: comment1.txt comment2.txt comment3.txt A little php formating would allow for leading zeros. Like this: comment001.txt comment002.txt comment003.txt ... comment025.txt I suggest leading zeros because sorting generally requires this because the following computer sorting issue: 1 10 11 12 13 14 15 16 17 18 19 2 20 21 ... 28 29 3 30 Leading zeros eliminates this proble up to the number of leading zeros. Example: 0001 is good up to 9999 before sorting problems occur. 001 is good up to 999 ... 01 is good up to 99 ... 1 is good up to 9 ... So you'll need to kind of guess how many files you'll have. This is kind of basic explaination of what to do, if you need more specific information like code samples, let me know. I always feel better when I figure it out on my own than just being told. Happy Scripting, vujsa |
|
|
|
Mar 16 2005, 01:02 PM
Post
#3
|
|
|
Premium Member Group: Members Posts: 208 Joined: 6-September 04 From: England Member No.: 315 |
Thankyou vujsa, that is what i this morning before i came on here to check. I wouldn't have thought about the leading 0 so it counts ok, thankyou for that.
|
|
|
|
![]() ![]() |
Similar Topics
|
Lo-Fi Version | Time is now: 22nd November 2008 - 04:16 PM |