Re: Sort question..

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Apr 25, 2012 at 3:16 PM, Karl-Arne Gjersøyen
<karlarneg@xxxxxxxxx> wrote:
> Hello again.
> I have a photo album that show all images in a specified directory.
> but I like to sort them by filename as one possibillity and random
> sort the photos as another feature.
> I don't know how to do this.. Here is my soruce-code:
>
> <!DOCTYPE html>
> <html lang="no">
>        <head>
>                <meta charset="utf-8">
>                <title>Bildegalleri</title>
>                <link rel="stylesheet" href="standard.css" media="screen">
>        </head>
>        <body>
>        <h1>Bildegalleri</h1>
>        <p><a href="bildegalleri.html">Last opp nye bilder</a> |&nbsp;
>        <a href="vis_bildegalleri.php?sorter_filnavn">Sorter på filnavn</a> |&nbsp;
>        <a href="vis_bildegalleri.php?tilfeldig_sortering">Tilfeldig sortering</a></p>
>        <ul>
> <?php
> // Skann katalogen og hent fram bildene
> $bilde =  new DirectoryIterator('bilder/');
>        while($bilde->valid()){
>                if(!$bilde->isDot()){
>                        if($_GET['sorter_filnavn']){
>                                echo '<li><img src="bilder/'.sort($bilde->getFilename()).'"
> alt="'.sort($bilde->getFilename()).'" height="200"></li>';
>                        } elseif($_GET['tilfeldig_sortering']) {
>                                echo '<li><img src="bilder/'.rand($bilde->getFilename()).'"
> alt="'.rand($bilde->getFilename()).'" height="200"></li>';
>                        } else {
>                                echo '<li><img src="bilder/'.$bilde->getFilename().'"
> alt="'.$bilde->getFilename().'" height="200"></li>';
>                        }
>                }
>        $bilde->next();
>        }
> unset($bilde);
> ?>
> </ul>
>        </body>
> </html>
>
> I will be lucky if somebode have time to help me out here.. I am sure
> it is some functions in php that can do the trick, but haven't found
> anything yet.
> Thanks for your time.
>
> Karl

Put all the files in an array, then sort with one of the sort functions[1].

- Matijn

[1] http://www.php.net/manual/en/array.sorting.php

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux