Help?!

Okay, sort of solved it for you… Seems there is a bug in PHP if certain servers are used and is it linked to
the DST time bugs. Very odd thing! You can get it to work without times for now. I am still trying to sort
out a fix for the times… Here is code for the filenames. You do not need the leading slash!
[php]
$dir = “NCFA/exports/”;
if (is_dir($dir_path)) {
if ($dir = opendir($dir_path)) {
while($file = readdir($dir)) {
if ($file != “.” and $file != “…”) echo $file . “
”;
}
closedir($dir);
} else {
echo “Could not open directory!”;
}
} else {
echo “Not a valid directory!”;
}
[/php]
I had to add in some debugging and error checking during tests and left them in…
Once I sort out the modification time bug, I will post it to you…

This is very odd. I got the “Not a valid directory!” notice…

Very sorry, fast typing fingers… I set it to $dir not $dir_path Change the first line!

Excellent! That worked to show me the files. Here’s to hoping we can get the date/time in there and maybe if its not too much work some formatting for a table? ;D

And by ‘we’ I meant you :stuck_out_tongue:

Yikes! Well, solved it for you… It was actually a bit of formatting and logic… Anyway, try this one…
As you will see, you can alter the formatting of the time as you wish. I just made it simple. Looks good in my
tests. As far as a table? I do not know what you mean. Do you mean you want to dump the time and name
into a small table with just two cols?

[php]
$dir_path = “NCFA/exports/”;
if (is_dir($dir_path)) {
if ($dir = opendir($dir_path)) {
$file_list = array();
while($file = readdir($dir)) {
if ($file != “.” and $file != “…”) $file_list[] = date(“Y m d”, filectime($dir_path . “/” . $file)) . ": " . $file;
}
closedir($dir);
krsort($file_list);
foreach($file_list as $filename) {
echo $filename . “
”;
}
} else {
echo “Could not open directory!”;
}
} else {
echo “Not a valid directory!”;
}
[/php]
And, this is sorted newest at the top and oldest at the bottom. That can be changed as needed, too…

That is starting to look good!

Yes, I meant a table with two columns if that can be done w/titles as well (in bold preferably?)…

So here’s the code I’m working with now. I adjusted the sort and timestamp…

[code]<?PHP

$dir_path = "NCFA/exports/";
if (is_dir($dir_path)) {
   if ($dir = opendir($dir_path)) {

$file_list = array();
while($file = readdir($dir)) {
if ($file != “.” and $file != “…”) $file_list[] = $file . " - " . date(“M d - h:i:s e”, filectime($dir_path . “/” . $file));

      }         
      closedir($dir);
     asort($file_list);
     foreach($file_list as $filename) {
        echo $filename . "<br>";
     }
  } else {
    echo "Could not open directory!";
 }

} else {
echo “Not a valid directory!”;
}

?>[/code]

Question… is there a way to change the $filename for each one to what I have put in the legend??

Well, that is just a little more tricky. But, all of the data is sorted now and inside the array. So you just
have to display it formatted as you want. Something like this would work… Oh, note that the way that
it is created is allows more than one file to have the same date/time as that can happen. So, the array
holds a combined date-time-filename to use as the sort key. The array does not keep them apart. So,
to fix that, we would just pull them apart to display in separate cols… Like this…

[php]
$dir_path = “NCFA/exports/”;
if (is_dir($dir_path)) {
if ($dir = opendir($dir_path)) {
$file_list = array();
while($file = readdir($dir)) {
if ($file != “.” and $file != “…”) $file_list[] = date(“Y m d”, filectime($dir_path . “/” . $file)) . ": " . $file;
}
closedir($dir);
krsort($file_list);
echo “

”;
foreach($file_list as $filename) {
echo “”;
}
echo “
TIMESTAMP FILENAME
” . substr($filename,0,10) . “ ” . substr($filename,12) . “
”;
} else {
echo “Could not open directory!”;
}
} else {
echo “Not a valid directory!”;
}
[/php]

They don’t appear to be sorted in any fashion at all…

http://cfa-football.com/NCFA.php

Also, want to repeat this question before it gets buried:
Question… is there a way to change the $filename for each one to what I have put in the legend??

EDIT: Disregard, I just put the asort() back in there above the foreach() statment.

Heeee! YES! I always say, ANYTHING can be done in programming… Just takes logic, thought and luck!

So, you would need to have an array of the legend and team name. Oh, I just put in TIMESTAMP and the
FILENAME, you can change those. Also, you might want to center them like this:
echo “

”;
Normally, you would do all this alignment, bolding and the such using CSS, but…

Now, to display the legend’s instead of the filenames, you can just do a table lookup. You would have to
grab the number off the filename which is very easy. So, Team36.coa has the 36 in the 5th and 6th position.
So, that is just substr($filename, 5, 2) would give you a 36. Then, you can look that up in your array. OR,
even easier just create an array of the legends and the matching filenames.

Well, how do you have the legends stored at this point? Is it in an array or do you have it in a database?
There are tons of ways to do this, but, you already have them. Explain to me how you currently store them.

TIMESTAMP FILENAME

Okay, two ways to do that… Easy to do and does not matter of the order…

Normally to create an array, you would use some code like this.
(Note this is for arrays with a keys and a values…)

$team_array = array(
“20” => “Boston”,
“21” => “Iowa”,
“99” => “Robmeister”
);
This is fairly easy as you would just enter the $key and the real value of it. You would be able to use this
array in both the top and bottom displays. For the top, you would do an asort on it and then display it like
this:
foreach($team_array as $key=>$team) {
echo “

Team " . $key . " - " . $team”;
}
Of course that is just a guess based on your page your posted…
Then, in the lower display, you would have to do a table lookup to handle the new display. The thing to do
is to pull out the key from the filename and then look up the team name. It would be done something like
this…
[php]
foreach($file_list as $filename) {
echo “ ” . $team_array(substr($filename, 5, 2)) . “ ” . substr($filename,12) . “ ”;
}
[/php]
As you see, it pulls the team from the new team array by using a key plucked from the filename. Now, this
was based on filenames with only 1 to 99 in them. If there were more than 99, you would have to do a
bit of trickery to adjust for that…

Hope that makes sense! I’m head’n to bed soon…

I toss something out.

[php]$files = array(
‘Team34.coa’,
‘Team43.coa’,
‘Team86.coa’,
‘Team99.coa’,
‘Team340.coa’,
‘Team112.coa’,
);

$teams = array(
34 => ‘Mavericks’,
99 => ‘Bulldogs’,
112 => ‘Bulls’,
340 => ‘Magic’,
);

foreach( $files as $file ){
// remove non-digits from string (filenames)
$id = preg_replace("/[^0-9]/", “”, $file);

// check if the numbers in the files have a legend
// associated to it. If it does, display it.
if ( array_key_exists($id, $teams)){
echo “

{$teams[ $id ]}

”;
}
}[/php]

The NCAA has 128 teams… so I tried the second script but I have no idea where to place it?!

What second script?

The one you posted.

The first array was just in place of actually having an array of files, like you’ve been working on. The second is your legend.

What is in the loop can be used when you retrieve the files.

Here’s the code I’m using (as the second one only confused things for me…)

[code]

<?PHP date_default_timezone_set('EST'); //NOTE: Change to EDT when Daylight Savings Time Begins $dir_path = "NCFA/exports/"; if (is_dir($dir_path)) { if ($dir = opendir($dir_path)) { $file_list = array(); while($file = readdir($dir)) { if ($file != "." and $file != "..") $file_list[] = $file . " - " . date("M d - h:i:s e", filectime($dir_path . "/" . $file)); } $team_array = array( "16" => "Syracuse", "20" => "Indiana", "21" => "Iowa", "24" => "Ohio State", "29" => "Wisconsin", ); echo ""; asort($file_list); foreach($file_list as $filename) { echo ""; ****613**** } echo "
FILENAME TIMESTAMP
" . $team_array(substr($filename, 5, 2)) . " " . substr($filename,12) . "
"; } else { echo "Could not open directory!"; } } else { echo "Not a valid directory!"; } ?>[/code]

This is giving me the error:
Fatal error: Function name must be a string in /home/content/29/8946729/html/NCFA.php on line 613

Is this line 613?

[php]if ($file != "." and $file != "..") $file_list[] = $file . " - " . date("M d - h:i:s e", filectime($dir_path . "/" . $file));[/php]

No, it is this one (which I marked above as well):

             echo "<tr><td>" . $team_array(substr($filename, 5, 2)) . "</td><td>" . substr($filename,12) .  "</td></tr>"; ****613****
Sponsor our Newsletter | Privacy Policy | Terms of Service