Images nach modifydatum sortieren

Einklappen
X
 
  • Filter
  • Zeit
  • Anzeigen
Alles löschen
neue Beiträge

  • Images nach modifydatum sortieren

    Ich habe eine Galleryscritp gemacht und habe vor es nach datum zu sortieren, dass die neuste upgeloadeten Images als erstes angezeigt werden. Ich habe das Forum durchsucht aber keine richtige lösung die mir passt gefunden, vieleicht findet ihr eine gute lösung für micht.

    Script:
    PHP-Code:
     if (!$view)
       {
          
    $dir opendir($subdir);
          echo 
    "<table align='center' cellpadding='5' cellspacing='0' style=\"border:1px solid black; empty-cells:show\">";
          while (
    $file readdir($dir))
          {
          if (
    eregi("^".$_GET['id']."_"$file)) {
              
    $imagechecker = @getimagesize($subdir"/" .$file);
              if (
    $imagechecker[2] == OR $imagechecker[2] == 2)
              {
                
    $zaehler ++;
                if (
    $count == 1){echo "<tr>";}
                echo 
    showpicture($file$imagewidth$subdir$shadow);
                if (
    $count $colums) {$count++;}
                else {
    $count 1; echo "</tr>";}
          }
          }
          }
          
    closedir($dir);
          echo 
    "</table>";
        } 

  • #2
    Bilder in ein array laden, das als key die filemtime() (oder so ähnlich) hat und dann mit entsprechenden Sortiermethoden für arrays sortieren... ksort() oder so ähnlich (einfach mal ins Manual schauen da findest du sicher dazu etwas)

    Kommentar


    • #3
      Dies bringt mir eigentlich nicht so recht weiter, ich brauche ein Beispiel code um es zu verstehen. Ich weiss, es ist eine nicht sehr leichte frage.

      Kommentar


      • #4
        Du würdest dir doch viel leichter tun und deinen PHP Code einfacher halten wenn du das ganze aus einer DB ausliest bzw. hineinschreibst.

        Ansonsten kann ich mich nur an em's Post anschliessen:
        Hier mal die links zur manual Klickst du
        Klickst du #2
        What?! Wer bist du denn?

        Kommentar


        • #5
          lustisch... in dem ksort-Beispiel auf php.net ist ein syntax-Fehler

          Kommentar


          • #6
            Bilder in ein array laden, das als key die filemtime()...
            Und wenn zwei Bilder zur gleichen Sekunde hochgeladen wurden, dann überschreibt er ein Element...
            Ich würde ein Array mit den Namen der Datei als Index und dem Filedatum als einziges Element angeben und dann usort() verwenden.
            PHP-Code:
            function cmp($a$b)
            {
               if (
            $a == $b) {
                   return 
            0;
               }
               return (
            $a $b) ? -1;
            }
            usort($array,'cmp');
            //direkt aus dem Manual 
            Müsste so in dieser Richtung funzen.

            Gruss

            tobi
            Gutes Tutorial | PHP Manual | MySql Manual | PHP FAQ | Apache | Suchfunktion für eigene Seiten

            [color=red]"An error does not become truth by reason of multiplied propagation, nor does truth become error because nobody sees it."[/color]
            Mohandas Karamchand Gandhi (Mahatma Gandhi) (Source)

            Kommentar


            • #7
              Ich habe jetzt alles durchforstet und ausprobiert und eine nicht ganz fertie lösung gefunden.

              Bei diesem Script wird es vom kleinsten zu grössten datum sortiert, aber ich möchte es gerade umgekehrt machen.
              PHP-Code:
              $dir opendir("images");
              while (
              $file readdir($dir))
              {
              if (
              eregi("^1_"$file)) {
              $imagechecker = @getimagesize("images/" .$file);
              if (
              $imagechecker[2] == OR $imagechecker[2] == 2)
              {
              $date date ("d.m.Y H:i:s"filemtime("images/" .$file));
              $date2[] = array ('datum'=>$date);
              sort ($date2);
              foreach (
              $date2 as $date3); {
              echo 
              $date3[datum]."<br>";
              }
              }
              }
              }
              closedir($dir); 
              Dies gibt das aus:
              19.04.2006 20:03:08
              19.04.2006 20:03:50
              19.04.2006 20:06:22
              19.04.2006 20:06:30
              19.04.2006 20:07:22

              mit rsort ($date2, SORT_NUMERIC); wird es aber komischerweise so rauskommen:
              19.04.2006 20:03:08
              19.04.2006 20:03:08
              19.04.2006 20:03:50
              19.04.2006 20:06:22
              19.04.2006 20:06:30

              Fehler: die ersten zwei arrays sind doppelt und nicht richtig sortiert.

              Wist ihr was ich da falsch mache?

              Kommentar


              • #8
                z.B. ev so ?
                PHP-Code:
                for($i=count(date2)-1;$i>=0;$i-=1) {
                    echo 
                date2[$i];

                Gruss

                tobi
                Gutes Tutorial | PHP Manual | MySql Manual | PHP FAQ | Apache | Suchfunktion für eigene Seiten

                [color=red]"An error does not become truth by reason of multiplied propagation, nor does truth become error because nobody sees it."[/color]
                Mohandas Karamchand Gandhi (Mahatma Gandhi) (Source)

                Kommentar


                • #9
                  hmm komme nicht mehr nach, bei mir kommt nur mist raus

                  Was ist da jetzt falsch? wie muss es aussehen?

                  PHP-Code:
                  $date date ("d.m.Y H:i:s"filemtime("images/" .$file));
                  $date2[] = array ('datum'=>$date);
                  rsort ($date2SORT_NUMERIC);
                  foreach (
                  $date2 as $date3); {
                  for(
                  $i=count(date3)-1;$i>=0;$i-=1) {
                  echo 
                  $date3[datum][$i]."<br>";
                  }

                  Zuletzt geändert von oKin3; 19.04.2006, 20:11.

                  Kommentar


                  • #10
                    PHP-Code:
                    foreach ($date2 as $date3); {
                    for(
                    $i=count(date3)-1;$i>=0;$i-=1) { 
                    Weisst du überhaupt was du machst ? Nimm die foreach komplett raus. Ich hatte in meinem Code ja auch keine drinnen. Nimm nur die for Schleife und arbeite mit $date2

                    Gruss

                    tobi
                    Gutes Tutorial | PHP Manual | MySql Manual | PHP FAQ | Apache | Suchfunktion für eigene Seiten

                    [color=red]"An error does not become truth by reason of multiplied propagation, nor does truth become error because nobody sees it."[/color]
                    Mohandas Karamchand Gandhi (Mahatma Gandhi) (Source)

                    Kommentar


                    • #11
                      Naja, dann sieht es so aus oder?
                      PHP-Code:
                      $date date ("d.m.Y H:i:s"filemtime("images/" .$file));
                      $date2[] = array ('datum'=>$date);
                      rsort ($date2SORT_NUMERIC);
                      for(
                      $i=count(date2)-1;$i>=0;$i-=1) {
                      echo 
                      $date2[$i]."<br>";

                      Da kommt das raus:
                      Array
                      Array
                      Array
                      Array
                      Array

                      Ich habe leider keine ahnung von arrays

                      Kommentar


                      • #12
                        PHP-Code:
                        $date2[] = array ('datum'=>$date);
                        //besser so
                        $date2[] = $date
                        Gruss

                        tobi
                        Gutes Tutorial | PHP Manual | MySql Manual | PHP FAQ | Apache | Suchfunktion für eigene Seiten

                        [color=red]"An error does not become truth by reason of multiplied propagation, nor does truth become error because nobody sees it."[/color]
                        Mohandas Karamchand Gandhi (Mahatma Gandhi) (Source)

                        Kommentar


                        • #13
                          aha und jetzt sollte die rsort funktion gerade umgekehrt wirken, aber dies ist leider nicht si, weshalb?

                          PHP-Code:
                          $date2[] = $date;
                          rsort ($date2SORT_NUMERIC); 
                          zeigt:
                          19.04.2006 20:03:08
                          19.04.2006 20:03:50
                          19.04.2006 20:06:22
                          19.04.2006 20:06:30
                          19.04.2006 20:07:22

                          Kommentar


                          • #14
                            Mal mit SORT_STRING probiert ?

                            Gruss

                            tobi
                            Gutes Tutorial | PHP Manual | MySql Manual | PHP FAQ | Apache | Suchfunktion für eigene Seiten

                            [color=red]"An error does not become truth by reason of multiplied propagation, nor does truth become error because nobody sees it."[/color]
                            Mohandas Karamchand Gandhi (Mahatma Gandhi) (Source)

                            Kommentar


                            • #15
                              Ja, habe fast alles ausprobiert immer das gleiche oder etwas falsches :S

                              Kommentar

                              Lädt...
                              X