Précédent   Forum des professionnels en informatique > PHP > PHP & SGBD > PHP & MySQL
PHP & MySQL Forum d'entraide sur les fonctions MySQL avec PHP. Avant de poster -> FAQ MySQL, Cours MySQL et Sources MySQL. Pour les questions concernant le moteur MySQL plutôt que les fonctions PHP, merci d'utiliser le forum MySQL.
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse Proposer ce sujet en actualité
 
Outils de la discussion
Publicité
Vieux 08/03/2010, 11h38   #1
Invité de passage
 
Inscription : avril 2008
Messages : 53
Détails du profil
Informations forums :
Inscription : avril 2008
Messages : 53
Points : 3
Points : 3
Par défaut Readdir par ordre de date

Bonjour,
je n'arrive vraiment pas a réaliser un ordre de triage de dossier par leur date de création c'est-a-dire le nouveau dossier sois en tête du listage (du récent au ancien) voici mon code php:

Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<?php
function pagination($conteneur_bd_debut, $conteneur_bd_fin, $conteneur_pg_debut, $conteneur_pg_fin, $page, $nbr_par_page, $nbr_liens, $dossier){
$tableau = array(); 
if(is_dir($dossier) {
$dir = opendir($dossier) or die('Impossible d\'ouvrir le dossier');
 
while (false !== ($file = readdir($dir)) {
if ($file != '.' && $file != '..' && $file != 'index.php' && $file != 'index-xml.php') {
$tableau[] = $file;
}
}
}
$total = count($tableau);
$nbr_pages = ceil($total/$nbr_par_page);
if(!isset($page)){
$page = '1';
}
if($nbr_liens != $nbr_pages){
$nbr_liens = $nbr_pages;
}
if($page >= $nbr_pages){
$page = $nbr_pages;
}
$liens = ceil($nbr_liens/2);
$pagination_debut = $page-$liens;
if($pagination_debut < '1'){
$pagination_debut = 1;
$pagination_fin = $nbr_liens;
}
$filmes = $nbr_par_page * $nbr_pages;
if(!isset($pagination_fin)){
$pagination_fin = $page+$liens;
if($pagination_fin > $nbr_pages){
$pagination_fin = $nbr_pages+1;
}
}
echo $conteneur_bd_debut;
$page_fin = $page*$nbr_par_page;
$page_debut = $page_fin-$nbr_par_page;
for ($a=$page_debut; $a<$page_fin; $a++){
	if(isset($tableau[$a])){
	echo $tableau[$a];
}
else{ echo "";
}
}
echo $conteneur_bd_fin, $conteneur_pg_debut;
if($page > '0'){
$precedent = $page-0;
$acces_precedent = '<a id="pagination" href="?page='.$precedent.'"><span>&#9668; Précédent</span></a> ';
}
else{
$acces_precedent = False;
}
if($pagination_debut > '0'){
$acces_debut = '';
$rognage_precedent = '<span style="font-family:Arial, Helvetica, sans-serif;
	font-size:12px;
	text-decoration:none;
	color:#0063a5;"></span>';
}
else{
$acces_debut = False;
$rognage_precedent = False;
}
echo $acces_debut, $acces_precedent, $rognage_precedent;
for ($b=$pagination_debut; $b<$pagination_fin; $b++){
$numero = $b;
$pointeur = str_replace($page,'<span>'.$page.'</span>',$numero);
$chaine.= '<a id="pagination" href="?page='.$b.'">'.$pointeur.'</a> <span id="pagination" >|</span> ';
$pointeur = str_replace($chaine,'<span>'.$page.'</span>',$chaine);
}
echo $chaine;
if($pagination_fin < $nbr_pages){
$rognage_suivant = '<span style="font-family:Arial, Helvetica, sans-serif;
	font-size:12px;
	text-decoration:none;
	color:#0063a5;"></span>';
$acces_page_fin = '<a id="pagination" href="?page='.$nbr_pages.'">'.$nbr_pages.'</a>';
$acces_fin = '';
}
else{
$rognage_suivant = False;
$acces_page_fin = False;
$acces_fin = False;
}
if($page < $nbr_pages){
$suivant = $page+1;
$acces_suivant = ' <a id="pagination" href="?page='.$suivant.'">Suivant &#9658;</a></center>';
}
else{
$acces_suivant = False;
}
echo $rognage_suivant, $acces_page_fin, $acces_suivant, $acces_fin;
echo $conteneur_pg_fin;
}
?>
(s.v.p pour les explication soyez aussi clair que possible (je suis noob en php) et ce script je l'ai trouvé sur le net et je l'ai modifié)

Merci d'avance !

Dernière modification par k3vin ; 09/03/2010 à 16h21.
k3vin est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 08/03/2010, 13h40   #2
Modérateur
 
Avatar de sabotage
 
Homme Vincent
Inscription : juillet 2005
Messages : 14 929
Détails du profil
Informations personnelles :
Nom : Homme Vincent

Informations forums :
Inscription : juillet 2005
Messages : 14 929
Points : 16 381
Points : 16 381
Actuellement tes éléments doivent être lu, les plus anciens en premier.
Il suffit donc d'inverser le tableau :
Code :
$tableau = array_reverse($tableau);
sabotage est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 08/03/2010, 16h16   #3
Invité de passage
 
Inscription : avril 2008
Messages : 53
Détails du profil
Informations forums :
Inscription : avril 2008
Messages : 53
Points : 3
Points : 3
J'ai rajouter le bous de code que vous avez proposer sabotage ! mais voici ce que apache m'affiche :
Code :
Warning: array_reverse() [function.array-reverse]: The argument should be an array in C:\xampp\htdocs\index.php on line 3
k3vin est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 08/03/2010, 16h28   #4
Modérateur
 
Avatar de sabotage
 
Homme Vincent
Inscription : juillet 2005
Messages : 14 929
Détails du profil
Informations personnelles :
Nom : Homme Vincent

Informations forums :
Inscription : juillet 2005
Messages : 14 929
Points : 16 381
Points : 16 381
Tu l'as bien mis après la boucle while ?
sabotage est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 08/03/2010, 16h48   #5
Invité de passage
 
Inscription : avril 2008
Messages : 53
Détails du profil
Informations forums :
Inscription : avril 2008
Messages : 53
Points : 3
Points : 3
Oui en effet, le problème s'est qu'il a inversé juste les nom sa veux dire au lieu de commencé par A il a commencé par Z ..! mais ce n'est pas ce que je veux !
moi je veux que les dossier sois classé du récent au plus ancien! merci.
k3vin est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 08/03/2010, 17h04   #6
Modérateur
 
Avatar de sabotage
 
Homme Vincent
Inscription : juillet 2005
Messages : 14 929
Détails du profil
Informations personnelles :
Nom : Homme Vincent

Informations forums :
Inscription : juillet 2005
Messages : 14 929
Points : 16 381
Points : 16 381
Hum effectivement readdir ne retourne pas les fichiers par ordre d'enregistrement ; essaie comme ça :
Code :
1
2
3
4
5
while (false !== ($file = readdir($dir))) {
if ($file != '.' && $file != '..' && $file != 'index.php' && $file != 'index-xml.php') {
$tableau[filemtime($file)] = $file;
}
krsort($tableau);
sabotage est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 08/03/2010, 17h13   #7
Invité de passage
 
Inscription : avril 2008
Messages : 53
Détails du profil
Informations forums :
Inscription : avril 2008
Messages : 53
Points : 3
Points : 3
Pour chaque dossier il y a une erreur :

Code :
1
2
3
Warning: filemtime() [function.filemtime]: stat failed for Brushes in C:\xampp\htdocs\index.php on line 9
 
Warning: filemtime() [function.filemtime]: stat failed for Gradients in C:\xampp\htdocs\index.php on line 9
k3vin est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 08/03/2010, 17h24   #8
Modérateur
 
Avatar de sabotage
 
Homme Vincent
Inscription : juillet 2005
Messages : 14 929
Détails du profil
Informations personnelles :
Nom : Homme Vincent

Informations forums :
Inscription : juillet 2005
Messages : 14 929
Points : 16 381
Points : 16 381
Effectivement :
Code :
1
2
3
4
5
6
while (false !== ($file = readdir($dir))) {
if ($file != '.' && $file != '..' && $file != 'index.php' && $file != 'index-xml.php') {
$tableau[filemtime($_SERVER['DOCUMENT_ROOT'] . '/' . $dossier . '/' . $file)] = $file;
}
}
krsort($tableau);
sabotage est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 08/03/2010, 17h47   #9
Invité de passage
 
Inscription : avril 2008
Messages : 53
Détails du profil
Informations forums :
Inscription : avril 2008
Messages : 53
Points : 3
Points : 3
Maintenant il affiche plus les dossier il m'affiche juste la pagination et plus rien d'autre !
k3vin est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 08/03/2010, 18h46   #10
Modérateur
 
Avatar de sabotage
 
Homme Vincent
Inscription : juillet 2005
Messages : 14 929
Détails du profil
Informations personnelles :
Nom : Homme Vincent

Informations forums :
Inscription : juillet 2005
Messages : 14 929
Points : 16 381
Points : 16 381
Ce script est mal foutu.
Ajoute encore
Code :
$tableau = array_values($tableau);
sabotage est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 08/03/2010, 19h56   #11
Invité de passage
 
Inscription : avril 2008
Messages : 53
Détails du profil
Informations forums :
Inscription : avril 2008
Messages : 53
Points : 3
Points : 3
sabotage you are the best! t'es un dieu! merci beaucoup !
k3vin est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité Cette discussion est résolue.
Outils de la discussion



Fuseau horaire GMT +1. Il est actuellement 04h42.


 
 
 
 
Partenaires

Hébergement Web