Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Oct 2009
    Location
    Dallas,Tx USA
    Posts
    54
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Group results aplhabetically

    Hello

    I am getting the files from a directory, by using the code below.
    Now i want to have A B C D ...Z as hyperlinks and when we click on a particular letter it should show files starting with that letter only.
    Any help pleaze.....
    PHP Code:
    <?
                            $file_available 
    "FALSE";
                            if (
    $handle opendir('voicefiles')) {
                                while (
    false !== ($file readdir($handle)))
                                {
                                  if (
    $file != "." && $file != ".." )
                                   {
                                        
    $file_available "TRUE";
                                        break;
                                   }
                                }
                                
    closedir($handle);
                            }

                            if(
    $file_available != 'FALSE')
                            {
                            
    ?>

                                <?php
                                    
    if ($handle opendir('voicefiles')) {
                                      while (
    false !== ($file readdir($handle)))
                                      {
                                          if (
    $file != "." && $file != ".." )
                                           {
                                                
    $number $file;
                                                
    $chkbox "chkbox$number";
                                                
    $thelist '<a href="voicefiles/'.$file.'">'.$file.'</a><br>';?>
                                                <?echo $thelist;
                                           }
                                       }
                                     
    closedir($handle);
                                    }
                                
    ?>

                                <P><? //echo $thelist?></p>


                            <?
                            
    }
                            else
                            {
                                echo 
    "No Prompt files found";
                            }
                            
    ?>

  • #2
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    use scandir

    http://www.php.net/manual/en/function.scandir.php

    or put filename in a array and sort alphabeticaly when you finish.

    best regards

  • #3
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,502
    Thanks
    8
    Thanked 1,089 Times in 1,080 Posts
    PHP Code:
    <?php
    // Not sure how you're doing your A,B,C links, but from a URL link ...
    // like this, <a href="search.php?letter=B">B</a> ...

    // Get the letter to search for, from the URL.
    $l=strtolower($_GET['letter']);

                            
    $file_available "FALSE";
                            if (
    $handle opendir('voicefiles')) {
                                while (
    false !== ($file readdir($handle)))
                                {
                                  if (
    $file != "." && $file != ".." )
                                   {
                                        
    $file_available "TRUE";
                                        break;
                                   }
                                }
                                
    closedir($handle);
                            }

                            if(
    $file_available != 'FALSE')
                            {
                            
    ?>

                                <?php
                                    
    if ($handle opendir('voicefiles')) {
                                      while (
    false !== ($file readdir($handle)))
                                      {
    if (
    $file != "." && $file != ".." )
    {
       
    $testfile=strtolower($file);
       
    // Look at the first character of the lower-case filename.
       
    if (substr($testfile,1) == $l){                                      
          
    $number $file;
          
    $chkbox "chkbox$number";
          
    $thelist '<a href="voicefiles/'.$file.'">'.$file.'</a><br>';?>
          <?echo $thelist;
       }
                         }
                                       }
                                     
    closedir($handle);
                                    }
                                
    ?>

                                <P><? //echo $thelist?></p>


                            <?
                            
    }
                            else
                            {
                                echo 
    "No Prompt files found";
                            }
    ?>

  • #4
    New Coder
    Join Date
    Oct 2009
    Location
    Dallas,Tx USA
    Posts
    54
    Thanks
    4
    Thanked 0 Times in 0 Posts
    hey thank you so much it worked like a charm


  •  

    Posting Permissions

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