Afficher plusieures images + liens aléatoire?

Résolu/Fermé
smed_79 Messages postés 1288 Date d'inscription dimanche 21 septembre 2008 Statut Contributeur Dernière intervention 17 mars 2017 - 17 déc. 2010 à 02:52
smed_79 Messages postés 1288 Date d'inscription dimanche 21 septembre 2008 Statut Contributeur Dernière intervention 17 mars 2017 - 17 déc. 2010 à 14:07
Bonjour,
pour afficher une image + un lien aléatoirej'utilise le code:

<?php
$homeurl = "http://www.top-favoris./" ;
$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 : http://img50.xooimage.com/files/b/4/2/capture-238a82d.jpg

merci


1 réponse

JavaMafia.com
17 déc. 2010 à 04:01
Bonjour,
c très facile il suffit d'utiliser une boucle par exemple :

for($i=0;$i<count($img);$i++)
{
echo '<a href="' . $homeurl . '' . $img[$i][1] . '" ><img src="' . $imgurl . '' . $img[$i][0] . '"></a>';

}

Bonne Chance :)
7
smed_79 Messages postés 1288 Date d'inscription dimanche 21 septembre 2008 Statut Contributeur Dernière intervention 17 mars 2017 843
17 déc. 2010 à 04:37
merci tu m'as beaucoup aidé :) j'apprécie.

maintenant si j'ai 20 images + 20 liens comment afficher un nombre limité par exemple 5 ?
0
JavaMafia.com
17 déc. 2010 à 13:13
il suffit de remplacer count($img) par 5 sur la boucle
après shuffle($img); biensur :)

for($i=0;$i<5;$i++)
{
echo '<a href="' . $homeurl . '' . $img[$i][1] . '" ><img src="' . $imgurl . '' . $img[$i][0] . '"></a>';
}
0
smed_79 Messages postés 1288 Date d'inscription dimanche 21 septembre 2008 Statut Contributeur Dernière intervention 17 mars 2017 843
17 déc. 2010 à 14:07
c'est parfait :D probleme résolu encore merci ;)
0