If statement

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
cschotch
Forum Newbie
Posts: 8
Joined: Thu Dec 12, 2002 4:56 pm

If statement

Post 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;
User avatar
nathus
Forum Commoner
Posts: 49
Joined: Thu Dec 12, 2002 6:23 pm

Post 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.
Post Reply