Hoi,

ik heb een image map met ongeveer 20 foto's erin. ik heb ze in een array gezet en wil ze sorteren van hoog naar laag(20 t/m 1).

de images heten dus : 1.gif, 2.gif, 3.gif, 4.gif, 5.gif ..... enzovoort.

maar als ik de image nu sorteer met rsort() of ksort() of alle andere sort() functies, het lukt maar niet, ik zie dan steeds dat het sorteert op deze volgorde:
15, 14, 13, 12, 11, 10, 1, 9, 8, 7, 6, 5, 4, 3, 2, terwijl ik juist van hoog naar laag wil hebben.
op php.net staat over natsort() en dat doet precies wat ik wil, maar dat werkt ook niet bij mij??

iemand een idee?

hier mijn code:

<?
$aantal_foto_per_pagina = '1'; //aantal plaatjes op 1 pagina
$locatie = 'images/'; //map van afbeeldingen

//$files = array('13.gif','12.gif','11.gif','Kopie van 15.gif', '10.gif', '9.gif', '8.gif', '7.gif', '6.gif', '5.gif', '4.gif', '3.gif', '2.gif', '1.gif');
//file is een array
$files = array();
//tel de map images op
$a0 = count($files);
// for loop door de map images
for ($p=0;$p <= $a0; $p++){

//hieronder hoeft niks veranderd te worden
if (!isset($_GET['pagina'])) { $pagina = 1; } else { $pagina = $_GET['pagina']; }
$dir = opendir($locatie);

// Haal de gegevens uit dir
while (false !== ($file = readdir($dir))) {

if (($file !== ".") and ($file !== "..")) {


$files[$p] = ($file);
$p++;
//natsort($files);
rsort($files);
//echo $files[$p];
}

$a0 = count($files);
$a1 = ($a0/$aantal_foto_per_pagina);
$a2 = round($a1);
if ($a1 > $a2) {
$a2++;
}
}
}
echo "<table border='1'><tr>";
$i = '1';
while ($i != ($a2 + 1)) {
//als pagina 1 is.
if ($pagina == $i) {
//variable is aantal_per_pagina * 1
$j = (($aantal_foto_per_pagina * $i)-$aantal_foto_per_pagina);
//variable is + 1
$afb = ($j + 1);
//terwijl variable ongelijk is aan aantal_foto_per_pagina
while ($j != ($aantal_foto_per_pagina * $i)) {
//als afbeelding kleiner is dan count(files)
if ($afb > $a0) {
//variable is aantal_foto_per_pagina * $i
$j = ($aantal_foto_per_pagina * $i);
}
else {
//echo images
//rsort($files);
//ksort($files);
echo "<td><img src=\"$locatie".$files[$afb]."\"></td>";
$afb++;
$j++;
}
}

echo"</tr></table>";
echo"<center>";
//pagina nummers met links
$l = '1';
echo "<br><br>";
while ($l != ($a2 -0)){
if ($l == $pagina){
echo "<b>[$l]</b> ";
}
else {
echo "<a href=\"" . $_SERVER['PHP_SELF'] . "?pagina=$l\">[$l]</a> ";
}
$l++;
}
echo"</center>";

}
$i++;
}

?>
thijs schreef op 27.03.2007 14:34
Ja je kan doormiddel van [php]explode[/php] de extentie eruithalen daarna sorteren en erweer aan plakken.


ok mooi dan doe ik dat, snapte eerst niet wat explode deed, maar begin het nu te snappen.

ok mensen ik ben weer tevreden.

K3
hij werkt nu prima!

Hier de complete script:

<?
$aantal_foto_per_pagina = '1'; //aantal plaatjes op 1 pagina
$locatie = 'images/'; //map van afbeeldingen
//$files = array('13.gif','12.gif','11.gif','Kopie van 15.gif', '10.gif', '9.gif', '8.gif', '7.gif', '6.gif', '5.gif', '4.gif', '3.gif', '2.gif', '1.gif');
//file is een array
$files = array();
//tel de map images op
$a0 = count($files);
// for loop door de map images
for ($p=0;$p <= $a0; $p++){

//hieronder hoeft niks veranderd te worden
if (!isset($_GET['pagina'])) { $pagina = 1; } else { $pagina = $_GET['pagina']; }
$dir = opendir($locatie);

// Haal de gegevens uit dir
while (false !== ($file = readdir($dir))) {

if (($file !== ".") and ($file !== "..")) {
list($file, $ext) = explode(".", $file);
list($main, $sub, $include) = explode("/", $PHP_SELF);

$files[$p] = ($file);
$p++;
//natsort($files);
rsort($files);
//echo $files[$p];
}

$a0 = count($files);
$a1 = ($a0/$aantal_foto_per_pagina);
$a2 = round($a1);
if ($a1 > $a2) {
$a2++;
}
}
}
echo "<table border='1'><tr>";
$i = '1';
while ($i != ($a2 + 1)) {
//als pagina 1 is.
if ($pagina == $i) {
//variable is aantal_per_pagina * 1
$j = (($aantal_foto_per_pagina * $i)-$aantal_foto_per_pagina);
//variable is + 1
$afb = ($j + 1);
//terwijl variable ongelijk is aan aantal_foto_per_pagina
while ($j != ($aantal_foto_per_pagina * $i)) {
//als afbeelding kleiner is dan count(files)
if ($afb > $a0) {
//variable is aantal_foto_per_pagina * $i
$j = ($aantal_foto_per_pagina * $i);
}
else {
//echo images
//rsort($files);
//ksort($files);
echo "<td><img src=\"$locatie".$files[$afb]."\"></td>";
$afb++;
$j++;
}
}

echo"</tr></table>";
echo"<center>";
//pagina nummers met links
$l = '1';
echo "<br><br>";
while ($l != ($a2 -0)){
if ($l == $pagina){
echo "<b>[$l]</b> ";
}
else {
echo "<a href=\"" . $_SERVER['PHP_SELF'] . "?pagina=$l\">[$l]</a> ";
}
$l++;
}
echo"</center>";

}
$i++;
}

?>

Reageren