|
|
A Php Gallery Commenting Script Question... - i am working on a php script... | ||
Discussion by overture with 2 Replies.
Last Update: March 16, 2005, 1:02 pm | |||
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.
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.
Wed Mar 16, 2005 Reply New Discussion
php has a built in ID function that generates an alphanumeric value based on microtime.
See Also
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
See Also
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
Wed Mar 16, 2005 Reply New Discussion
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.
Wed Mar 16, 2005 Reply New Discussion
How Can I Use Php Online On My Pc? Do I have to download a program? (4)
|
(4) Mail() Not Working
|
Index




