Page 2 of 2
Posted: Mon Aug 12, 2002 6:58 pm
by fatalcure
change this:
Code: Select all
for ($i=0; $i <= sizeof($myArray); $i++) {
to this:
Code: Select all
for ($i=0; $i <= sizeof($myArray) - 1; $i++) {
that will get rid of the error.
I've basically writtin the whole script for you, some things u have to figure out on your own, if you only want it to be publised on that day, play around with the if ($date >= $filedate) statement.
Posted: Mon Aug 12, 2002 9:26 pm
by WizyWyg
fatalcure wrote:change this:
Code: Select all
for ($i=0; $i <= sizeof($myArray); $i++) {
to this:
Code: Select all
for ($i=0; $i <= sizeof($myArray) - 1; $i++) {
that will get rid of the error.
I've basically writtin the whole script for you, some things u have to figure out on your own, if you only want it to be publised on that day, play around with the if ($date >= $filedate) statement.
Im still getting that error.
Warning: Failed opening 'files/' for inclusion (include_path='.;c:\apache\php\pear') in c:\apache\htdocs\test\test.php on line 38
Even with the correction.
Line 38=
include($path);
And I've been playing around with (on the older code)
if ($date >= $filedate)
And the results are:
if ($date >= $filedate) = shows content of files in directory prior to and including today's
if ($date = $filedate) = shows content of all files in directory including future dates.
if ($date <= $filedate) = shows content of files in diretory for future dates including today.
if ($date < $filedate) = shows content of files in diretory for future dates not including today.
if ($date > $filedate) = shows content of files in directory prior to today.
But now im getting it listed out of order:
test 8-7-2002 (file name 7 August 2002.html)
test 8-8-2002 (file name 8 August 2002.html)
test 8-9-2002 (file name 9 August 2002.html)
test 8-12-2002 (file name 12 August 2002.html)
test 8-10-2002 (file name 10 August 2002.html)
test 8-11-2002 (file name 11 August 2002.html)
8-10 and 8-11 files were ceated after 8-12 file (all three posted on 8-8).
I've been playing with the code all day, and these are the questions Im coming up with. PHP.net doesn't address any of these concerns since 90% of the answers deal with managing with a database, which I am not running. If i had a database to work with, I wouldn't have to be concerned with 90% of this. Working from flat file systems suck, but Im stuck with it.
Posted: Mon Aug 12, 2002 10:09 pm
by fatalcure
is it including any of the files or is it giving the error on the first try?
Is your $location correct?? Do you have a directory called files?
How is it listing out of order? what do u mean?
Posted: Tue Aug 13, 2002 3:13 am
by twigletmac
When doing comparisons in PHP you want this:
not
as that will just set $date = $filedate no matter what $date was originally. You should have a look at
comparison operators.
Try doing,
to find out what $path actually is so that you can check if it exists (since the error is saying that it doesn't).
PHP has a number of functions for dealing with files and directories and for working with arrays:
http://www.php.net/manual/en/ref.filesystem.php
http://www.php.net/manual/en/ref.dir.php
http://www.php.net/manual/en/ref.array.php
the manual does tend to have lots of examples especially in the user-contributed notes and it really is your friend.
One last thing:
file name 11 August 2002.html
you should really avoid having spaces in file names either use underscores instead or just delete them.
Mac
Posted: Tue Aug 13, 2002 2:13 pm
by WizyWyg
twigletmac wrote:When doing comparisons in PHP you want this:
not
as that will just set $date = $filedate no matter what $date was originally. You should have a look at
comparison operators.[/b]
Okay changing it to the above produces nothing.
None of the content of the files shows up.
but if $date = $filedate then the content shows up.
If $date >= (or <= or > or <) is used, the content shows up.
Try doing,
to find out what $path actually is so that you can check if it exists (since the error is saying that it doesn't).[/b]
All it echoes is files/files/files/files/files/files/files/files/
I've been up and down that manual. Its all greek to me. I learn by what the code is and breaking it down to see how it works.
One last thing:
file name 11 August 2002.html
you should really avoid having spaces in file names either use underscores instead or just delete them.
Mac
I didn't know if the spaces were needed to compare the time() in the $date define. Does it work without the spaces?
Posted: Tue Aug 13, 2002 2:41 pm
by WizyWyg
fatalcure wrote:is it including any of the files or is it giving the error on the first try?
Is your $location correct?? Do you have a directory called files?
How is it listing out of order? what do u mean?
None of the files' contents are being included.
Yes I have a directory name files since I have the original code posted above it and that one is working semi-correctly (its still posting out of order).
Posted below are the screen caps of what is happening:
So in this one, the code is correct as it lists all the contents of the files in the files directory, but its posting out of order. Aug 12 and 13's contents are coming right after Aug. 9 and Aug 10 and 11 are after those. Aug 12 and 13's files were created before Aug 10 and 11 (file creation date). Does the file creation date have to do anything with why its posting out of order?
In this one, you can see that nothing has changed for the $path since its referring to the same directory as the above code. The only thing different is the $MyArray
; instead of $file . And when I do an echo $path; to see what is up as suggested by Mac all I get as a result is files/files/files/files/files/ (by the way I have both .html versions as well ast .txt versions of the files in the files directory)
And how do i get it so that if Aug 14 (for example) comes around that the content from 14 August 2002.html is only shown until the next file (say Aug 20, 2002) come around?
Posted: Tue Aug 13, 2002 3:24 pm
by WizyWyg
Okay fixed the path problem:
needed a $ in the $myArray[$i]
But its still posting out of sequence Ascending order ( Aug 13 should be on top and Aug 7 should be at the bottom)
And what would be the code to display the contents of only 1 file until the next date/file in the directory?
Posted: Tue Aug 13, 2002 3:48 pm
by WizyWyg
I figured out the problem with the out of sequence. Its pulling the time from when the FILE Was last CREATED (or modified) and not from the given file name.
Because when I went in and created all new files for the dates (8/7 - 8/15) in order, it is now displaying correctly (in order).
The second code however, still doesn't post it in descending order.
Posted: Tue Aug 13, 2002 4:15 pm
by WizyWyg
Okay something really odd.
I went to edit one of the html file (12 August 2002.html) so now it has a modified time and date that is AFTER 15 August 2002.html, but now its displaying correctly in Ascending order. Now, how can i do it so its in descending order since the 2nd code isn't parsing the array in reverse order.
Posted: Tue Aug 13, 2002 4:54 pm
by twigletmac
Follow the advice you got on devshed on renaming your files. Maybe the main problem is that you should've started instead of with a finished script with learning how to do each part in turn. The reason why the manual is Greek to you is because you're trying to run before you can walk - you need to understand the more basic concepts before you can grasp the more advanced ones. Basically by just getting the code written for you your not learning as much as you would do by doing it yourself no matter what you say - whenever you need to change a little bit of functionality you have to ask someone to rewrite your code.
You'll be surprised at how quickly you'll be able to get your own code up to the level of the code you currently have - the key difference is in writing it yourself you'll have a much more in depth idea of how it's working and by starting simple and getting more complex you'll find it easier to debug when things go wrong. You'll also find you'll probably get more (and faster help) on the forums when you're trying to sort your own code rather than code that someone else has written for you that you want rewritten. It may be an idea to do a bunch of tutorials as these should aid someone who learns by example as they provide lots of these.
Mac
Posted: Tue Aug 13, 2002 4:56 pm
by WizyWyg
twigletmac wrote:Follow the advice you got on devshed on renaming your files. Maybe the main problem is that you should've started instead of with a finished script with learning how to do each part in turn.
That's the ONLY way I know how to learn. Im a visual person. I need to see the complete code so I can understand how it works. Being presented to me in pieces doesn't help me. I've always learned "backwards". Take things apart then put them back together again (which is how i learned to fix computers, vcr's, radios, and tv's).
Actually, I rather work from DB's since i know how to code from data stored in DB. I've never had to work from Flat files so the coding is different for it. I just can't see the similarities in obtaining from a DB (which is easier to get information from) than to handle it in a flat file system.
I did follow the advice in DEvshed but Its still not working.
There aren't many tutorials for Flat file based retrieval of data for php, and every tutorial i run into is if you have a DB. I dont.
So I followed the advice at DevShed but this is the problem Im encountering:
Though this is the results Im getting now just by changin the file names to YYYYMMDD.html format
test 8-8-2002
test 8-9-2002
test 8-10-2002
test 8-11-2002
test 8-12-2002
test 8-13-2002
test 8-7-2002
so I decided to do just a readdir to see what is in my directory:
Code: Select all
<?php
if ($handle = opendir('files')) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
echo "$file<br>\n";
}
}
closedir($handle);
}
?>
And its diplaying this:
20020808.html
20020809.html
20020810.html
20020811.html
20020812.html
20020813.html
20020814.html
20020815.html
20020807.html
So, why is 20020807.html being listed last?
Posted: Wed Aug 14, 2002 12:45 am
by e+
He he, I'd of loved to see how you learnt to read and write, pride and prejudice for you, give me spot the dog any day

. It doesn't sound like your code is to complicated it's just it's very hard to learn 20 odd intertwined concepts at once much easier one at a time. Twigletmac isn’t lying to you it’s how she learnt to code (honest).
If you are having trouble try puling the code to bits and get little bits of script working one at a time and not trying to get them to all work together. A modular approach to coding always helps when you come back to editing it.
Kind Regards
e+
Posted: Wed Aug 14, 2002 2:57 am
by twigletmac
WizyWyg wrote:That's the ONLY way I know how to learn. Im a visual person. I need to see the complete code so I can understand how it works. Being presented to me in pieces doesn't help me. I've always learned "backwards". Take things apart then put them back together again (which is how i learned to fix computers, vcr's, radios, and tv's).
But if you don't understand the different things that go into making your code how can you do anything with it? If you learn by reverse engineering then the way to do that with code is to go through it line by line, looking up functions in the manual to see what they do and following variables through as they are modified and returned. Otherwise you've got a black box of code - stuff goes in other stuff comes out - and you don't have the ability to do anything if the other stuff coming out is not what you want or would expect.
You say there's no good tutorial on flat file management well there are lots on manipulating arrays and dates which is mainly what that code was doing. Working with an array is the same whether it's data from a flat file or data from a database or data you've set yourself in the script. Formatting the date and working with date functions is the same whether from flat file, database, other code. You need to understand how these bits work much more than you need to know how a graphics card works when you plug it into a PC. Coding is very different to building a PC, it's less structured you can do things in hundreds of different ways there's no set way to perform each action, each person can do it differently. You can take apart a piece of code and put it back completely differently - mixing everything up and using different functions and still have code that does exactly the same thing.
Mac
Posted: Wed Aug 14, 2002 9:02 am
by fatalcure
amen twig

Posted: Wed Aug 14, 2002 2:21 pm
by WizyWyg
But if you don't understand the different things that go into making your code how can you do anything with it? If you learn by reverse engineering then the way to do that with code is to go through it line by line, looking up functions in the manual to see what they do and following variables through as they are modified and returned. Otherwise you've got a black box of code - stuff goes in other stuff comes out - and you don't have the ability to do anything if the other stuff coming out is not what you want or would expect.
I got it to work correctly in the end. That means I learned something from it. SORRY, but I am not a programmer or a coder. Im an artist by trade that has to use coding to do what I need to do that HTML doesn't do. This kind of attitude is not warranted or needed. All I came here is to ask for help on trying to achieve what I wanted to do. I normally work with DB's which IS easier in my opinion to work with. IF I had a db to work with I wouldn't be here. If you guys treat people and newbies to PHP like this all the time, why do you even bother to answer questions posted? Maybe there should a be NEWBIE forum where people learning php can go to without the lectures, or the attitude? I was referred here by someone else because the books he had and I had did not cover flat files.
Dont assume that everyone who is learning PHP has the same level of expertise as you do or learns the same way you do. WE are not all alike. I learn by visual examples, breaking things down until I understand how they work as a whole. IF you can't understand this, Im sorry, but there are a lot of people like me in the world.
You say there's no good tutorial on flat file management well there are lots on manipulating arrays and dates which is mainly what that code was doing.
NONE of which were helpful. PLEASE point out a tutorial that explains how to pull content from flat files based on date....nope. That's why I came here.
Working with an array is the same whether it's data from a flat file or data from a database or data you've set yourself in the script. Formatting the date and working with date functions is the same whether from flat file, database, other code.
I've never had problems with pulling data from a DB based on date. I just didn't understand how it applied to flatfiles.
You need to understand how these bits work much more than you need to know how a graphics card works when you plug it into a PC. Coding is very different to building a PC, it's less structured you can do things in hundreds of different ways there's no set way to perform each action, each person can do it differently. You can take apart a piece of code and put it back completely differently - mixing everything up and using different functions and still have code that does exactly the same thing.
And making a flower in photoshop or painting a mural can be done 100 different ways. At least something was done, created, and it worked.
My questions were answered, thanks to fatalcure and others. I owe them a greatful thanks for their patience. I fixed the array problem and now the information displays correctly.