IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Langage PHP Discussion :

Afficher une vidéo aléatoire dans page HTML


Sujet :

Langage PHP

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre confirmé
    Profil pro
    Inscrit en
    Juin 2005
    Messages
    113
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2005
    Messages : 113
    Par défaut Afficher une vidéo aléatoire dans page HTML
    BOnjour à tous,

    je cherche a afficher une vidéo aléatoirement (dans une liste pré établie), dans un calque sur une page HTML.

    J'ai essayé de faire une selection aléatoire d'une vidéo en PHP, mais je n'arrive pas a afficher la vidéo dans un calque. Je ne sais pas quoi mettre dans la balise DIV

    Voici le code actuel

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    <body>
    <?php
    $nbvideo=3;
     
    $nomvideo[1]="<object width="320" height="256"><param name="movie" value="http://www.dailymotion.com/swf/video/xddw53?background=%23171D1B&foreground=%23F7FFFD&highlight=%230EFF00&autoPlay=0&hideInfos=0&width=320&additionalInfos=1&colors=background%3A171D1B%3Bforeground%3AF7FFFD%3Bspecial%3A0EFF00%3B"></param><param name="allowFullScreen" value="true"></param><param name="allowScriptAccess" value="always"></param><embed type="application/x-shockwave-flash" src="http://www.dailymotion.com/swf/video/xddw53?background=%23171D1B&foreground=%23F7FFFD&highlight=%230EFF00&autoPlay=0&hideInfos=0&width=320&additionalInfos=1&colors=background%3A171D1B%3Bforeground%3AF7FFFD%3Bspecial%3A0EFF00%3B" width="320" height="256" allowfullscreen="true" allowscriptaccess="always"></embed></object>"
     
    $nomvideo[2]="<object width="320" height="179"><param name="movie" value="http://www.dailymotion.com/swf/video/xd76r0?background=%23171D1B&foreground=%23F7FFFD&highlight=%230EFF00&autoPlay=0&hideInfos=0&width=320&additionalInfos=1&colors=background%3A171D1B%3Bforeground%3AF7FFFD%3Bspecial%3A0EFF00%3B"></param><param name="allowFullScreen" value="true"></param><param name="allowScriptAccess" value="always"></param><embed type="application/x-shockwave-flash" src="http://www.dailymotion.com/swf/video/xd76r0?background=%23171D1B&foreground=%23F7FFFD&highlight=%230EFF00&autoPlay=0&hideInfos=0&width=320&additionalInfos=1&colors=background%3A171D1B%3Bforeground%3AF7FFFD%3Bspecial%3A0EFF00%3B" width="320" height="179" allowfullscreen="true" allowscriptaccess="always"></embed></object>"
     
    $nomvideo[3]="<object width="320" height="240"><param name="movie" value="http://www.dailymotion.com/swf/video/xd4wiy?background=%23171D1B&foreground=%23F7FFFD&highlight=%230EFF00&autoPlay=0&hideInfos=0&width=320&additionalInfos=1&colors=background%3A171D1B%3Bforeground%3AF7FFFD%3Bspecial%3A0EFF00%3B"></param><param name="allowFullScreen" value="true"></param><param name="allowScriptAccess" value="always"></param><embed type="application/x-shockwave-flash" src="http://www.dailymotion.com/swf/video/xd4wiy?background=%23171D1B&foreground=%23F7FFFD&highlight=%230EFF00&autoPlay=0&hideInfos=0&width=320&additionalInfos=1&colors=background%3A171D1B%3Bforeground%3AF7FFFD%3Bspecial%3A0EFF00%3B" width="320" height="240" allowfullscreen="true" allowscriptaccess="always"></embed></object>"
     
    srand((double)microtime()*1000000);
    $affvideo=rand(1,$nbvideo);
    ?>
    <div id="Layer1" style="position:absolute; width:613px; height:302px; z-index:1; left: 9px; top: 75px;"></div>
    </body>

    Merci d'avance pour vos conseils !

  2. #2
    Rédacteur
    Avatar de Halleck
    Homme Profil pro
    Consultant PHP
    Inscrit en
    Mars 2003
    Messages
    597
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 39
    Localisation : France, Loiret (Centre)

    Informations professionnelles :
    Activité : Consultant PHP

    Informations forums :
    Inscription : Mars 2003
    Messages : 597
    Par défaut
    Un simple echo devrait suffire non ?
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    echo $nomvideo[$affvideo]
    Je te conseille de revoir ton code, qui ne peut pas marcher en l'état :
    • en PHP il n'est pas utile de déclarer la taille des tableaux
    • tu as des problèmes avec tes variables, au niveau des doubles quotes

    Je te conseillerai plutôt de regrouper tes infos dans un tableau, mais c'est juste un conseil :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    $videos = array(
    	array(
    		'width' => '320'
    		,'height' => '256'
    		,'src' => 'url_de_la_video_1'
    	)
    	,array(
    		'width' => 320
    		,'height' => 179
    		,'src' => 'url_de_la_video_2'
    	)
    	,array(
    		'width' => 320
    		,'height' => 240
    		,'src' => 'url_de_la_video_3'
    	)
    );
     
    // prendre une vidéo au hasard
    $video_a_afficher = $videos[rand(0,sizeof($videos) - 1)];
     
    // on passe au html
    ?>
     
    <div id="Layer1" style="position:absolute; width:613px; height:302px; z-index:1; left: 9px; top: 75px;">
    	<object width="<?php echo $video_a_afficher['width'];?>" height="<?php echo $video_a_afficher['height'];?>"><param name="movie" value="<?php echo $video_a_afficher['src'];?>"></param><param name="allowFullScreen" value="true"></param><param name="allowScriptAccess" value="always"></param><embed type="application/x-shockwave-flash" src="h<?php echo $video_a_afficher['src'];?>" width="<?php echo $video_a_afficher['width'];?>" height="<?php echo $video_a_afficher['height'];?>" allowfullscreen="true" allowscriptaccess="always"></embed></object>
    </div>

Discussions similaires

  1. Comment positionner vidéo flash dans page html à un endroit précis
    Par cutpeter56 dans le forum Mise en page CSS
    Réponses: 6
    Dernier message: 28/12/2010, 16h39
  2. Afficher une variable javascript dans du HTML
    Par sandrine49 dans le forum Général JavaScript
    Réponses: 1
    Dernier message: 29/08/2009, 18h07
  3. Afficher contenu de $_GET dans page HTML
    Par donnadieujulien dans le forum Langage
    Réponses: 7
    Dernier message: 30/01/2009, 01h48
  4. affichage d une variable js dans page html
    Par rragnarok dans le forum Général JavaScript
    Réponses: 5
    Dernier message: 15/03/2008, 15h25

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo