Précédent   Forum des professionnels en informatique > PHP > Langage > Débuter
Débuter Forum d'entraide pour débuter en PHP. Avant de poster -> Cours PHP, FAQ PHP, Outils PHP, etc.
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 17/12/2010, 02h59   #1
Invité régulier
 
Inscription : novembre 2008
Messages : 24
Détails du profil
Informations forums :
Inscription : novembre 2008
Messages : 24
Points : 7
Points : 7
Par défaut afficher plusieures images + liens aléatoire

Bonjour,

pour afficher une image + un lien aléatoire j'utilise le code:

Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<?php
$homeurl = "http://www.top-favoris.co.cc/" ;
$imgurl = "http://i64.servimg.com/u/f64/11/94/21/24/" ;
$img = array(
   0 => array("fifa10.gif", "sport/fifa.html"),
   1 => array("uefa10.jpg", "sport/uefa.html"),
   2 => array("cafonl10.gif", "sport/cafonline.html"),
   3 => array("afc10.gif", "sport/the-afc.html"),
   4 => array("concac10.gif", "sport/concacaf.html"),
   5 => array("livesc10.jpg", "sport/livescore.html")
);
srand ((double)microtime()*1000000);
shuffle($img);
echo '<a href="' . $homeurl . '' . $img[0][1] . '" ><img src="' . $imgurl . '' . $img[0][0] . '"></a>';
?>
je cherche comment afficher plusieures images + liens aléatoire ?

un exemple sur cette image :



merci
smed79 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 17/12/2010, 04h41   #2
Invité régulier
 
Inscription : novembre 2008
Messages : 24
Détails du profil
Informations forums :
Inscription : novembre 2008
Messages : 24
Points : 7
Points : 7
j'ai résolu mon problème avec une boucle

Code :
1
2
3
4
5
for($i=0;$i<count($img);$i++)
{
echo '<a href="' . $homeurl . '' . $img[$i][1] . '" ><img src="' . $imgurl . '' . $img[$i][0] . '"></a>';
 
}
smed79 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 17/12/2010, 09h04   #3
Modérateur
 
Avatar de Vil'Coyote
 
Développeur Web
Inscription : février 2008
Messages : 3 302
Détails du profil
Informations personnelles :
Âge : 31
Localisation : France, Marne (Champagne Ardenne)

Informations professionnelles :
Activité : Développeur Web

Informations forums :
Inscription : février 2008
Messages : 3 302
Points : 4 480
Points : 4 480
heu dans ton code j'vois plus trop l'aléatoire en fait là.
Vil'Coyote est déconnecté   Envoyer un message privé Réponse avec citation 10
Vieux 20/12/2010, 10h23   #4
Membre expérimenté
 
Avatar de bricecol
 
Brice Colucci
Développeur informatique
Inscription : avril 2007
Messages : 357
Détails du profil
Informations personnelles :
Nom : Brice Colucci
Âge : 23

Informations professionnelles :
Activité : Développeur informatique

Informations forums :
Inscription : avril 2007
Messages : 357
Points : 544
Points : 544
Envoyer un message via MSN à bricecol Envoyer un message via Skype™ à bricecol
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
<?php
$homeurl = "http://www.top-favoris.co.cc/";
$imgurl = "http://i64.servimg.com/u/f64/11/94/21/24/";
$img = array(
  0 => array("fifa10.gif", "sport/fifa.html"),
  1 => array("uefa10.jpg", "sport/uefa.html"),
  2 => array("cafonl10.gif", "sport/cafonline.html"),
  3 => array("afc10.gif", "sport/the-afc.html"),
  4 => array("concac10.gif", "sport/concacaf.html"),
  5 => array("livesc10.jpg", "sport/livescore.html")
);
 
// avec doublons possibles
$nbImages = count($img);
for ($i=0; $i<$nbImages; $i++){
  $imgChoisie = $img[rand(0, $nbImages-1)];
  printf('<a href="%s"><img src="%s"/></a>', $homeurl.$imgChoisie[1], $imgurl.$imgChoisie[0]);
}
 
// sans doublons
$imgTmp = $img;
do{
  $nbImages = count($imgTmp);
  $indice = rand(0, $nbImages-1);
  printf('<a href="%s"><img src="%s"/></a>', $homeurl.$imgTmp[$indice][1], $imgurl.$imgTmp[$indice][0]);
  unset($nbImages[$indice])
} while ($nbImages);
?>
__________________
"Computers are like Old Testament gods ; Lots of rules and no mercy"
[ Les ordinateurs sont comme les dieux de l’Ancien testament ; Beaucoup de règles et aucune pitié. ] Joseph Campbell

Dénoncez les arnaques internet !
Consulter mon C.V. en ligne.
bricecol est déconnecté   Envoyer un message privé Réponse avec citation 10
Vieux 20/12/2010, 23h05   #5
Invité régulier
 
Inscription : novembre 2008
Messages : 24
Détails du profil
Informations forums :
Inscription : novembre 2008
Messages : 24
Points : 7
Points : 7
Citation:
Envoyé par bricecol Voir le message
Code :
1
2
3
4
 
// avec doublons possibles
et
// sans doublons
merci, justement les images double c'est été mon 2eme probleme.
c'est parfait j'apprécie votre aide.
smed79 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 04/10/2011, 18h17   #6
Membre du Club
 
Inscription : juin 2007
Messages : 336
Détails du profil
Informations forums :
Inscription : juin 2007
Messages : 336
Points : 48
Points : 48
Bonjour,

Cela correspond à mon problème également, en cherchant à avoir des images aléatoires sans doublons, avec votre code :
Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<?php
$homeurl = "http://www.top-favoris.co.cc/";
$imgurl = "http://i64.servimg.com/u/f64/11/94/21/24/";
$img = array(
   0 => array("image1.jpg", "sport/fifa.html"),
   1 => array("image2.jpg", "sport/uefa.html"),
   2 => array("image3.jpg", "sport/cafonline.html"),
   3 => array("image4.jpg", "sport/the-afc.html"),
   4 => array("image5.jpg", "sport/concacaf.html"),
   5 => array("image6.jpg", "sport/livescore.html")
);
 
 
 
// sans doublons
$imgTmp = $img;
do{
  $nbImages = count($imgTmp);
  $indice = rand(0, $nbImages-1);
  printf('<a href="%s"><img src="%s"/></a>', $homeurl.$imgTmp[$indice][1], $imgurl.$imgTmp[$indice][0]);
  unset($nbImages[$indice])
} while ($nbImages);
?>
J'obtiens l'erreur : Parse error: syntax error, unexpected '}', expecting ';' in C:\wamp\www\index.php on line 29 - la ligne 29 correspondant au while, d'ou peut provenir cette erreur ?

Merci.
yuyu599 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 04/10/2011, 19h11   #7
Responsable Développement Web

 
Avatar de Bovino
 
Homme Didier Mouronval
Développeur Web
Inscription : juin 2008
Messages : 13 802
Détails du profil
Informations personnelles :
Nom : Homme Didier Mouronval
Âge : 41
Localisation : France, Gironde (Aquitaine)

Informations professionnelles :
Activité : Développeur Web
Secteur : High Tech - Éditeur de logiciels

Informations forums :
Inscription : juin 2008
Messages : 13 802
Points : 35 807
Points : 35 807
Il ne faut pas copier coller à l'aveugle...
Il est évident qu'il y a un oubli de point-virgule à la fin de la ligne précédente :
Code :
unset($nbImages[$indice])
__________________
Pas de question technique par MP !
Tout le monde peut participer à developpez.com, vous avez une idée, contactez-moi !
Vous possédez un blog et aimeriez diffuser vos billets sur le forum, contactez-moi !
Mes formations video2brain : La formation complète sur JavaScriptJavaScript et le DOM par la pratiquePHP 5 et MySQL : les fondamentaux
Mon livre sur jQuery
Bovino est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 05/10/2011, 04h00   #8
Invité régulier
 
Inscription : novembre 2008
Messages : 24
Détails du profil
Informations forums :
Inscription : novembre 2008
Messages : 24
Points : 7
Points : 7
@Bovino merci pour la point-virgule

@yuyu599 voila le code que je continu à l'utiliser normalement n'y a pas d'erreur tu copier coller à l'aveugle

Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<?php
$homeurl = "http://www.top-favoris.co.cc/" ;
$imgurl = "http://i64.servimg.com/u/f64/11/94/21/24/" ;
$img = array(
  0 => array("el-kha10.gif", "algerie/elkhabar.html"),
  1 => array("achoro12.gif", "algerie/echoroukonline.html"),
  2 => array("ennaha10.gif", "algerie/ennaharonline.html"),
  3 => array("al-mas10.gif", "algerie/el-massa.html"),
  4 => array("al-faj10.gif", "algerie/al-fadjr.html"),
  5 => array("elayem10.jpg", "algerie/elayem-com.html"),
  6 => array("akher-10.gif", "algerie/akhersaa-dz.html"),
  7 => array("annasr10.gif", "algerie/annasronline.html")
);
srand ((double)microtime()*1000000);
shuffle($img);
for($i=0;$i<4;$i++) // afficher 4 images
{
echo '<a href="' . $homeurl . '' . $img[$i][1] . '" ><img src="' . $imgurl . '' . $img[$i][0] . '"></a>';
}
?>
smed79 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 05/10/2011, 15h10   #9
Membre du Club
 
Inscription : juin 2007
Messages : 336
Détails du profil
Informations forums :
Inscription : juin 2007
Messages : 336
Points : 48
Points : 48
Je vous remercie cela fonctionne à merveille :-)
yuyu599 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 +2. Il est actuellement 03h19.


 
 
 
 
Partenaires

Hébergement Web