|
|
|
|
Posté par
dracucharles, le mardi 13 mai 2008 à 09:56:22<?php
$nbimages=6; //nombre d'images au total
//chemin de mes images stocke dans un tableau
$nomimages[1]="images/labophy.jpg";
$nomimages[2]="images/3emeT4.jpg";
$nomimages[3]="images/secretariat.jpg";
$nomimages[4]="images/lavallee.jpg";
$nomimages[5]="images/ser_champ.jpg";
$nomimages[6]="images/batiment.jpg";
//génération de nombre aléatoire
$affimage1=rand(1,$nbimages);
$affimage2=rand(1,$nbimages);
$affimage3=rand(1,$nbimages);
$affimage4=rand(1,$nbimages);
$affimage5=rand(1,$nbimages);
$affimage6=rand(1,$nbimages);
//boucle de test pour ne pas avoir 2 images pareil
while(($affimage1==$affimage2) || ($affimage1==$affimage3) || ($affimage1==$affimage4) || ($affimage1==$affimage5) || ($affimage1==$affimage6) || ($affimage2==$affimage3) || ($affimage2==$affimage4) || ($affimage2==$affimage5) || ($affimage2==$affimage6) || ($affimage3==$affimage4) || ($affimage3==$affimage5) || ($affimage3==$affimage6) || ($affimage4==$affimage5) || ($affimage4==$affimage6) || ($affimage5==$affimage6)){
$affimage2=rand(1,$nbimages);
$affimage3=rand(1,$nbimages);
$affimage4=rand(1,$nbimages);
$affimage5=rand(1,$nbimages);
$affimage6=rand(1,$nbimages);
}
?>
//affichage dans un tableau
<table class='transparent'>
<tr><td class='transparent'><a href='index.php'><img src='./images/logo_2.gif' width='150'></a></td>
<td class='transparent'><img src='<?php echo $nomimages[$affimage1];?>' width='150'></td>
<td class='transparent'><img src='<?php echo $nomimages[$affimage2];?>' width='150'></td>
<td class='transparent'><img src='<?php echo $nomimages[$affimage3];?>' width='150'></td>
<td class='transparent'><img src='<?php echo $nomimages[$affimage4];?>' width='150'></td></tr>
</table>
Configuration: Windows XP Firefox 2.0.0.14
Bonjour,
Tu devrais trouver ton bonheur là: http://www.commentcamarche.net/forum/affich 1389643 php image aleatoire |
En fait j'ai déjà mes images aléatoires, mais j'ai fais en sorte que pour les images 1, 2, 3 et 4 que j'affiche dans mon tableau, aucune d'entre elles ne soient identiques. Mais si j'ajoute des images dans ma "collection" il y aura encore plus de tests dans ma boucle. Donc je ne sais pas s'il y a un moyen plus simple pour tester si mes images ne sont pas identiques.
Merci de vos réponses |
J'ai parfaitement compris ton probleme!
En effet, mon premier lien ne répondait pas à ton probleme! J'ai trouvé ce lien si non: http://www.lbb.org/script/Php/Images/Aleatoire/index.php C'est un "annuaire de script", je pense qu'il y en a un qui pourra t'intéresser. http://www.lbb.org/cgi-bin/script/detail.cgi?ID=6315 J'ai pas été voir le script par lui même, je me suis arreté à la description! |
Merci, mais je ne cherche pas de script tout fait, j'aimerais juste savoir s'il y a un moyen plus simple que la boucle que j'ai déjà. |
| 23/08 20h00 | Supprimer complètement un programme | Windows |
| 01/11 01h00 | Installation de programmes - Windows Installer CleanUp | Windows |
| 05/02 16h56 | [Windows] Programme invisible dans Ajout/Suppression | Windows |
| 27/02 15h12 | [Linux] Installer les programmes (gestion des paquets, compil) | Linux |
| 08/04 11h43 | [Windows 2000] Affichage Ajout/suppression de programmes | Windows 2000 |
| 24/07 21h25 | Prog DVB ne fonctionne plus | 9 |
| 24/07 20h25 | Trop de programme en cours | 6 |
| 24/07 12h24 | Comment changer les programme au démarrage | 11 |
| 23/07 19h25 | Programmer une action | 8 |
![]() | progeCAD 2008 - Vous recherchez une solution gratuite afin de vous familiariser avec le domaine du CAD ? Ce logiciel est fait pour vous.... | Catégorie: 3D Licence: Freeware/gratuit |
![]() | uTorrent - µTorrent est un client BitTorrent , c'est-à-dire un logiciel de téléchargement Peer-To-Peer (P2P) capable de gérer les... | Catégorie: Téléchargement Licence: Freeware/gratuit |
![]() | Windows XP SP2 - Les Service Packs constituent un moyen pratique, tout en un, d'accéder aux derniers pilotes, outils et améliorations en... | Catégorie: Librairies (DLL) Licence: Freeware/gratuit |
![]() | Word Viewer - La visionneuse Word Viewer vous permet d'ouvrir des documents Word 2003 et des documents créés avec toutes les versions... | Catégorie: Traitement de texte Licence: Freeware/gratuit |
![]() | Les Experts : Mort | Catégorie: Jeu vidéo PC | 29.95 € Amazon.fr |
![]() | Verbatim Mouse Wireless Programmable | Catégorie: Souris | 15.99 € Matrixx-media FR |
![]() | Tony Tough 2: A | Catégorie: Jeu vidéo PC | |
![]() | Speed-Link SL-8793 Medusa ProGamer | Catégorie: Casque audio |