Results 1 to 6 of 6

Thread: [RESOLVED] Need help on fixing my code that is suppose to highlight one file in a filelist

Threaded View

  1. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2001
    Location
    www.alexdata.com
    Posts
    484

    Thumbs up Re: [RESOLVED] Need help on fixing my code that is suppose to highlight one file in a

    So here is the full working code for a "simple FILE LISTER" with some extra functionality as to drawing the site differently, depending on what day it is...

    Live example: http://www.alexdata.com/CODEBASE/FileLister/

    PHP Code:
    <center><br><br>                                <!-- CENTER EVERYTHING ON THIS PAGE -->

    <?PHP
    $AllowedExtension
    =array('txt');                    //**List Of FileExtensions You Allow To Show**\\
    $FileCount=0;
    $TheDir=".";
    $DirectoryFiles=opendir("$TheDir");                //**The Directory, Where Your Files Are Stored**\\


    $TheDate date("d.F.Y");                        //**The Current Date Today**\\
    $TheTime date("\k\l\ \ H:i");                    //**The Current Time Right Now**\\
    $ThisDay date("D");                            //**This Days Short Name; ex: Sun**\\


    $WeekNumber=date("W");                            //**The Current Week Number**\\
    $NextWeekNumber=date("W")+1;                        //**The Next Weeks Number**\\


    $CheckWeek="ThisWeek: " $WeekNumber;            //**Checks This Weeks Number**\\
    $CheckNextWeek="NextWeek: " $NextWeekNumber;    //**Checks Next Weeks Number**\\
    ?>


    <?PHP                                            //**THIS WRITES THE TOP HEADER TEXT ON THE PAGE**\\
    Echo "<h3><i><u>Week:</u></i> " $WeekNumber " @@ <i><u>Day:</u></i> " $ThisDay " @@ <i><u>Date:</u></i> " $TheDate " @@ <i><u>Time:</u></i> " $TheTime "</h3>";

    Echo 
    "The Special Day we're looking for is: <b>".$ThisDay."</b> and if we are at that day, then that should highlight the file containing next weeks number: <b>".$NextWeekNumber."</b><br><br><br>";
    ?>


    <?PHP

    //**CHECKS ALL FILES IN DIRECTORY FOR ALLOWED EXTENSIONS AND ADD THEM TO THE ARRAY**\\
    while($CurrentFileName readdir($DirectoryFiles))
    //while-start
        
    if(in_array(strtolower(substr($CurrentFileName,-3)),$AllowedExtension))
        {
        
    $FileArray[]=$CurrentFileName;
        
    Sort($FileArray);
        
    Reset($FileArray);
        
    $FileCount=$FileCount+1;
        }
    //while-End

    //**WHEN DONE CHECKING THE DIRECTORY AND ADDING FILENAMES TO THE ARRAY**\\
    $TotalArrayFilenameCount=count($FileArray);            //**Count of Filenames in  the Array**\\
    $FileListWidth=2;                                    //**DEFINES HOW MANY FILES TO LIST PR ROW, BEFORE JUMPING TO NEXT LINE**\\
    $FileListCounter=0;                                    //**EMPTIES THE COUNTER FOR THE "HOW MANY FILES TO LIST PR ROW" HEHE**\\
    ?>

    <!-- START OF TABLE DESIGN -->
    <table cellpadding="10" cellspacing="10" style='border:3px; border-color:black; border-style:solid;' align="center" valign="center"><tr>

    <?PHP
    //** USE THE COUNTED FILENAMES IN THE ARRAY TO PROCESS THE DIFFRENT FILENAMES AND OUTPUT SOME RESULT**\\
    for($IncrementCount=0$IncrementCount $TotalArrayFilenameCount$IncrementCount++)
    //STARTS THE "FOR" LOOP\\
        //if($ThisDay=="Sun") <--ORIGINAL REMOVED FOR TEST PURPOSES    //**CHECKS TO SEE IF IT IS THE SPECIAL DAY TODAY**\\
        
    if($ThisDay==$ThisDay)                                    //**CHECKS TO SEE IF IT IS THE SPECIAL DAY TODAY**\\
        
    {
        
    //**IF THIS IS THE SPECIAL DAY THAT WE ARE LOOKING FOR THEN DO SPECIAL PROCEDURES FOR THIS DAY AND NEXT WEEK**\\
        //**SPECIAL**\\
        
    $ToFindNow=$NextWeekNumber;                            //**PUT THIS WEEKS NUMBER INTO THE ToFindNow VARIABLE**\\
        
    $ToLookNow=$FileArray[$IncrementCount];                //**THE ToLookNow VARIABLE GETS INFO FROM THE ARRAY RECORD EQUAL TO IncrementCount VARIABLE**\\
    //echo $NextWeekNumber;        
    //echo "SpecialDay";
        
    }
        else
        {
        
    //**THIS IS JUST ANY OTHER DAY THAN THE SPECIALDAY, DO NORMAL PROCEDURES FOR THIS WEEK**\\
        
    $ToFindNow=$WeekNumber;                                //**PUT THIS WEEKS NUMBER INTO THE ToFindNow VARIABLE**\\
        
    $ToLookNow=$FileArray[$IncrementCount];                //**THE ToLookNow VARIABLE GETS INFO FROM THE ARRAY RECORD EQUAL TO IncrementCount VARIABLE**\\
        //echo "NormalDay";
        
    }

        
    //**If a match is found, the if statement will evaluate to something non-false; you don't need to check the $Matches array**\\
        
    if(ereg($ToFindNow$ToLookNow$Matches))
        { 
    //EQUAL!!
        
    echo "<td style='border:1px; border-color:black; border-style:solid;'><a href='".$FileArray[$IncrementCount]."'><b>NextWeek: ".$FileArray[$IncrementCount]."</b></a></td>";
        
    //echo " STR:" . strripos($Matches[0],$ToLookNow) . " | " . (int)$Matches[0] . ":" . (int)$ToLookNow ."<br>";
        
    }
        else
        { 
    //DIFFERENT!!
        
    echo "<td style='border:1px; border-color:black; border-style:solid;'><a href='".$FileArray[$IncrementCount]."'><i>".$FileArray[$IncrementCount]."</i></a></td>";
        
    //echo " STR:" . strripos($Matches[0],$ToLookNow) . " | " . (int)$Matches[0] . ":" . (int)$ToLookNow ."<br>";
        
    }


    //**SETS THE DISPLAY OF FIlENAMES ON THE PAGE TO ROWS OF THREE FILES PR ROW**\\
    $FileListCounter=$FileListCounter+1;
    if ( 
    $FileListCounter==$FileListWidth ) {$FileListCounter=0; echo"</tr><tr>";}


    //ENDS THE "FOR" LOOP\\

    ?>

    <!-- END OF TABLE DESIGN -->
    </tr></table>




    <!-- REMOVED::
    //X ereg($ToFindNow, $ToLookNow, $Matches);                //**CHECK THE TWO STRINGS TO SEE IF THEY MATCH, AND PUT THE RESULT INTO ARRAY Matches**\\
    ////if($Matches[0] == $ToFindNow)
    ////if (In_String($ToFindNow,$ToLookNow,1))
    //X if((int)$Matches[0] == (int)$ToFindNow)                //**CHECK IF THE STRINGS ARE EQUAL**\\
    -->


    <!-- <br><br>THIS SHOULD ONLY HIGHLIGHT <b>ONE</b> FILE... RIGHT NOW IT HIGHLIGHTS MANY FILES  -->
    <br><br>WORKS NOW!!
    <!-- END -->
    Last edited by alexdata; Sep 23rd, 2009 at 12:20 PM.
    ***************
    Please use [highlight=vb] ..your code.. [/highlight] when posting code!

    When you have received the working answer to your question,
    please mark it as *SOLVED* + Your Questions Title ...using your Thread's Tool menu.


    Also try to point out what answer made it work for you, or edit your first post to contain a quote of the correct answer...

    Please Answer All Questions With Working Code Examples...


    My Unfinished Projects and My working Programs
    ***************

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width