I want to use arrays in my website (flat file for a guestbook), but despite
having read through countless online tutorials on the topic, I just can't
get my code to work.
I know there are guestbook scripts out there - but that doesn't help me
learn how to programme arrays !!!
The following is the code for the PHP (called externally), which does
execute...
<?php
// Setup of guestbook data to open and read from
$filename = "test.db";
$fh = fopen ($filename, "r") or die("Could not open guestbook file at this
time");
for($i = 0; $i < count($Date); $i++)
{
echo($Date[$i]."<br>");
}
echo('Number of arrays:'.count( $Date).'<BR>');
echo('Size of array:'.sizeof( $Date).'<BR>');
fclose($fh);
?>
The last two echo statements are to prove to me that the script is actually
running. The script is supposed to access the following file (test.db)
which contains the data....
$Date[0] = "Friday, March 14th 2003 - 04:28:45 AM";
$Date[1] = "Saturday, November 24th 2001 - 11:24:30 AM";
It doesn't matter if I leave it as $Date[] in the db file, the problem is
the same.
When the PHP script executes in the webpage, the two echo statements that
prove the script executed echos that the number of arrays is zero, and the
size of the array is also zero. I cannot get it to print out the contents
of the arrays into the webpage as I want it too.
It was suggested to me to use an include("test.d b") statement instead of
the whole fopen() fclose() stuff, but that jsut outputs the entire contents
of the file and performs no array checking (the file would have other
different arrays in it).
I can't understand why it is not working, after all it's very simple code.
Count how many $Date[] arrays there are in total in the file, then find the
first $Date[] array, print it to screen, then increment the count and
repeat the process to the next one until it gets to the last one. It
should work, but it is not.
Anyone help, it's really perplexing me.
Dariusz
having read through countless online tutorials on the topic, I just can't
get my code to work.
I know there are guestbook scripts out there - but that doesn't help me
learn how to programme arrays !!!
The following is the code for the PHP (called externally), which does
execute...
<?php
// Setup of guestbook data to open and read from
$filename = "test.db";
$fh = fopen ($filename, "r") or die("Could not open guestbook file at this
time");
for($i = 0; $i < count($Date); $i++)
{
echo($Date[$i]."<br>");
}
echo('Number of arrays:'.count( $Date).'<BR>');
echo('Size of array:'.sizeof( $Date).'<BR>');
fclose($fh);
?>
The last two echo statements are to prove to me that the script is actually
running. The script is supposed to access the following file (test.db)
which contains the data....
$Date[0] = "Friday, March 14th 2003 - 04:28:45 AM";
$Date[1] = "Saturday, November 24th 2001 - 11:24:30 AM";
It doesn't matter if I leave it as $Date[] in the db file, the problem is
the same.
When the PHP script executes in the webpage, the two echo statements that
prove the script executed echos that the number of arrays is zero, and the
size of the array is also zero. I cannot get it to print out the contents
of the arrays into the webpage as I want it too.
It was suggested to me to use an include("test.d b") statement instead of
the whole fopen() fclose() stuff, but that jsut outputs the entire contents
of the file and performs no array checking (the file would have other
different arrays in it).
I can't understand why it is not working, after all it's very simple code.
Count how many $Date[] arrays there are in total in the file, then find the
first $Date[] array, print it to screen, then increment the count and
repeat the process to the next one until it gets to the last one. It
should work, but it is not.
Anyone help, it's really perplexing me.
Dariusz
Comment