Darklighter Posted July 4, 2009 Share Posted July 4, 2009 I have run into an unusual problem for the first time while building my website. I have a recursive program that scans through many predefined folders and the subfolders it finds, looking for particular files. It then should update the global $counter variable and put it into the table that displays the results. But the $counter variable remains unchanged during this process. I have tried passing the "global" variable through every function, I have even tried a global array and adding to it, extracting the count()...Nothing seems to work. I do not understand why, as I have never had this problem before. but I have never used a recursive function either. Instead of calling a function, how can I use a GoTo command like in Visual Basic, telling the interpreter to jump to a specific line? For some reason, the value (object itself?) seems to be lost when I change functions, even if the variable is declared immediately after <?php....Below is a copy/paste of the code, which is easier to read in wordpad or php editor, because I like to indent my functions... <?php $array = array(""); print "<html> <head> <title>Article Statistics (EZHouseFixes.com ©Brandon Day)</title> <script type=\"text/javascript\" src=\"/Scripts/tooltip.js\"></script> <script type=\"text/javascript\" src=\"/Scripts/sortTable.js\"> <link rel=\"stylesheet\" href=\"CSS/sortTable.css\"/> </head> <table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" width=\"100%\"> <tr><td width=\"100%\"> <div id=\"TableContainer\" class=\"TableContainer\" style=\"height:600\"> <table class=\"scrollTable\" width=\"100%\"> <thead class=\"fixedHeader headerFormat\"> <tr> <td class=\"\" onclick=\"GoTop(); sortTable(this,0);\" title=\"Sort by Item Number\" width=\"35\" align=\"left\"> #<img src=\"/Images/desc.gif\" border=\"0\" width=\"10\" height=\"10\"></td> <td class=\"\" onclick=\"GoTop(); sortTable(this,0);\" title=\"Sort by Document Title\" width=\"160\" align=\"left\"> Document Title<img src=\"/Images/none.gif\" border=\"0\" width=\"10\" height=\"10\"></td> <td class=\"\" onclick=\"GoTop(); sortTable(this,0);\" title=\"Sort by Submittal Date\" align=\"left\" width=\"90\"> Date <img src=\"/Images/none.gif\" border=\"0\" width=\"10\" height=\"10\"></td> <td class=\"\" onclick=\"GoTop(); sortTable(this,0);\" title=\"Sort by User Rating\" align=\"left\" width=\"70\"> Rating<img src=\"/Images/none.gif\" border=\"0\" width=\"10\" height=\"10\"></td> <td class=\"\" onclick=\"GoTop(); sortTable(this,0);\" title=\"Sort by Page Path\" align=\"left\" width=\"190\"> Path<img src=\"/Images/none.gif\" border=\"0\" width=\"10\" height=\"10\"></td> <td class=\"\" onclick=\"GoTop(); sortTable(this,0);\" title=\"Sort by Hits\" align=\"left\" width=\"50\"> Hits<img src=\"/Images/none.gif\" border=\"0\" width=\"10\" height=\"10\"></td> <td class=\"\" onclick=\"GoTop(); sortTable(this,0);\" title=\"Sort by Document Size\" align=\"left\" width=\"60\"> Size<img src=\"/Images/none.gif\" border=\"0\" width=\"10\" height=\"10\"></td> <td class=\"\" onclick=\"GoTop(); sortTable(this,0);\" title=\"Sort by Experience Required\" align=\"left\" width=\"125\"> Difficulty<img src=\"/Images/none.gif\" border=\"0\" width=\"10\" height=\"10\"></td> <td class=\"\" align=\"left\" width=\"8\">Tools</td> </tr> </thead> <tbody class=\"scrollContent bodyFormat\" style=\"height:200px;\"> </thead> <tbody class=\"scrollContent bodyFormat\" style=\"height:200px;\">"; $fh = fopen("System Logs/HitCounter.txt","r"); $counter = fread($fh,filesize("System Logs/HitCounter.txt")+1); fclose($fh); $fh = fopen("System Logs/Visitors.txt","r"); $visitors = fgets($fh); fclose($fh); print "<form name=\"console\" action \"console.php\" method=post><input type=hidden name=\"action\" value=\"\"> <input type=hidden name=\"data\" value=\"\"><input type=hidden name=\"browse\" value=\"\"> <input type=hidden name=\"section\" value=\"\"><input type=hidden name=\"topic\" value=\"\"> <input type=hidden name=\"page\" value=\"\"><input type=hidden name=\"Username\" value=\"$Username\"> <input type=hidden name=\"Pwd\" value=\"$Pwd\"> This website has been visited <a href=/System%20Logs/Hits.txt target=\"console_details\">$counter times</a> by <a href=/System%20Logs/Visitors.txt target=\"console_details\">$visitors unique visitors</a> sinse May 21, 2009"; print "<script> function SetAction(act, info) { document.console.action.value = act; document.console.data.value=info; if (info.indexOf(\"/\") > -1){ arr = info.split(\"/\"); b=arr[0]; s=arr[1]; t=arr[2]; p=arr[3]; } if (act == 'delete' || act == 'hide' || act == 'profile' || act == 'edit'){ document.console.browse.value=b; document.console.topic.value=t; document.console.section.value=s; document.console.page.value=p; document.console.submit(); } else { alert('Function pending...!'); } } </script>"; function PrintNumericAverageRating($pth){ if (is_file( $pth)) { $fh = fopen($pth, "r"); while (! feof($fh)){ $r = $r + fgets($fh); $c++; } $a = round($r / $c,2); print $a; } else { print "0"; } } function ScanBrowse($dir, $articlecount) { if ($handle = opendir($dir)) { while ($fld = readdir($handle)){ clearstatcache(); if (is_dir($dir . '/' . $fld)) { if ($fld != "." && $fld != "..") { $a = explode("/", "$dir/$fld"); $depth = count($a); if ($depth == "4") { if (is_file("$dir/$fld/list.htm")) { ScanList ("$dir/$fld", $articlecount); } } else { ScanBrowse ($dir . '/' . $fld, $articlecount); } } } } } } function StartScan(){ ScanBrowse('Location', $articlecount); ScanBrowse('Task'); ScanBrowse('Trade'); } function ApplyFound ($pth, $Name, $Author, $Created, $Rating, $Location, $Size, $Difficulty, $counter, $articlecount) { $array[] = ""; $array[] = ""; $articlecount =$articlecount +1; $arr = explode("/", $pth); $b = $arr[1]; $s = $arr[2]; $t = $arr[3]; $p = $arr[4]; $cmd = "http://ezhousefixes.com/index.php?action=article&browse=$b§ion=$s&topic=$t&page=$Name"; $nav = str_replace("Home_Repairs > ", "", str_replace("/", " > ", $pth)); $lnk = "<a href=\"$cmd\" target=\"EZHF Main\">$Name</a>"; if ($trclass == "<tr>"){ $trclass ="<tr class=\"alternateRow\">"; } else { $trclass = "<tr>"; } print "\n $trclass<td valign=\"top\"> " . number_format(count($array)) . "</td> <td valign=\"top\">$lnk</td> <td valign=\"top\">$Created</td> <td valign=\"top\">"; PrintNumericAverageRating("$pth/$Name/Ratings.txt"); $spot = "$b/$s/$t/$Name"; print "</td> <td valign=\"top\">$nav</td> <td valign=\"top\">$counter</td> <td valign=\"top\">$Size</td> <td valign=\"top\">$Difficulty</td> <td valign=\"top\" align=\"center\"> <img src=\"Images/green-flag.png\" height=18 width=18 onClick=\"java script:SetAction('removeflag', '$spot');\"> <img src=\"Images/folder.jpg\" height=18 width=18 onClick=\"java script:SetAction('showfolder', '$spot');\"> <img src=\"Images/promote.jpg\" height=18 width=18> <img src=\"Images/edit.jpg\" height=18 width=18 onClick=\"java script:SetAction('editarticle', '$spot');\"> <img src=\"Images/delete.jpg\" height=18 width=18 onClick=\"java script:SetAction('delete', '$spot');\"> <img src=\"Images\hide.jpg\" height=18 width=18 onClick=\"java script:SetAction('hide', '$spot');\"> </td>\n </tr>\n"; } function ScanList($pth, $articlecount){ $fh = fopen($pth . "/list.htm", "r"); while (! feof($fh)){ $Name=""; $fc = fgets($fh); parse_str($fc); if ($Name != "") { $fh2 = fopen($pth . "/" . $Name . "/HitCounter.txt", "r"); $counter = fgets($fh2); fclose($fh2); ApplyFound($pth, $Name, $Author, $Created, $Rating, $Location, $Size, $Experience, $counter, $articlecount); } } fclose($fh); } ScanBrowse("Home_Repairs", $articlecount); ?> Link to comment Share on other sites More sharing options...
playcraft Posted July 4, 2009 Share Posted July 4, 2009 here is a simple script to throw each line into an array. You can then access any line via the array. <?php $handle = @fopen('yourfile...', "r"); if ($handle) { while (!feof($handle)) { $lines[] = fgets($handle, 4096); } fclose($handle); } ?> Notice the array is $line. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.