Page 1 of 1

If statement

Posted: Sun Dec 15, 2002 10:05 pm
by cschotch
This script is supposed to list the players and (depending on whether they were in the log file or not) it will list the name and then a 1 if they were on or 0 if they were not. The script works but it always gives a 0.

Code: Select all

<?php

function Chk_File($file) &#123;

$fp = fopen($file,"r") or die("Failed!");  
$end_report = fread($fp, filesize($filename));
  
$names&#1111;'Timmietie'] = 0;
$names&#1111;'Hoot'] = 0;
$names&#1111;'Jonesey'] = 0;

foreach(array_keys($names) as $value)&#123; 
    $names&#1111;$value] = substr_count($end_report, $value); 
&#125;  
foreach($names as $key=>$value) &#123; 
    echo "$key: ";//$names&#1111;$key] <br />\n"; 
    if ($value >= '1') echo "1";
    else echo "0";
    echo '<br />';
     
&#125; 
fclose($fp);  

&#125;
echo "<TABLE>\n";
echo "     <TR>\n";
$filename = array('tuesday.txt','wednesday.txt','thursday.txt');
for($i = 0; $i < count($filename); $i++) &#123;
     echo "          <TD>";
     Chk_File($filename&#1111;$i]);
     echo "          </TD>";
&#125;
echo "     </TR>\n";
echo "</TABLE>\n";

?>
I beleive the error is here....

Code: Select all

foreach($names as $key=>$value) &#123; 
    echo "$key: "; 
    if ($value >= '1') echo "1";
    else echo "0";
    echo '<br />';
&#125;

Posted: Sun Dec 15, 2002 10:53 pm
by nathus
in your Chk_File($file) function, you're referencing the file by the name $filename, so its setting the size it reads from your file to 0.