doumiao0498 2011-07-05 17:31
浏览 29
已采纳

显示数据库中的默认YouTube视频

I have a page on my site where at the top of the page, there is a youtube player and below the player is a bunch of video thumbnails that users can click. Clicking the thumbnail plays the video in the player.

I need a youtube video to display by default in the player box... this needs to be the FIRST result from the database

THE SPECIFICS

In videos.php, I have my header/footer and some other stuff. For displaying content on the page, I include displayvideos.php. The video player is also declared here and grabs the video ID from the address bar:

<iframe id="player" width="640" height="385" src="http://www.youtube.com/embed/<?php echo $_GET['id'] ?>?autoplay=1" frameborder="0"></iframe>

In displayvideos.php, all of my video thumbnails are displayed from a database. Clicking on the video thumbnail changes the id variable in the address bar to change the video being played.

What I need is a default video to be displayed, the first result from the database, when the user first loads into the page. I'm unsure how to do this as well as having the thumbnails below that will also change the video.

Here is my relevant SQL/PHP that populates the page

while ($row = mysql_fetch_array($result)) {
        $tubeID = $row['videoinfo'];
        $title = $row['title'];
            echo
                '<div class="vid"><p id="vidtitle">' . $title .  '</p><a href="videos.php?id=' . $tubeID . '&awayid=' . $awayid . '&homeid=' . $homeid . '&date=' . $date . '&time=' . $time . '&gameid=' . $gameid . '"><img src="http://img.youtube.com/vi/' . $tubeID . '/0.jpg" width="225" height="175"/><span class="play"></span> </a></div>';
}
  • 写回答

1条回答 默认 最新

  • dongyuji7309 2011-07-12 07:21
    关注

    Somewhere before:

    <iframe id="player" width="640" height="385" src="http://www.youtube.com/embed/<?php echo $_GET['id'] ?>?autoplay=1" frameborder="0"></iframe>
    

    Add this code:

    <?php
      // There is no id or the id is set to default so play the default video
      if(!isset($_GET['id']) || $_GET['id'] == 'default'){
        // Get the first result in the database
        $defaulttubeID = mysql_fetch_assoc(mysql_query("SELECT `videoinfo` FROM `DATABASE`.`TABLE` LIMIT 0,1"));
        // Change the $_GET['id'] variable to our new video id
        $_GET['id'] = $defaulttubeID['videoinfo'];
      }
    ?>
    

    If you link your users to either videos.php or videos.php?id=default it should play the first result from the MySQL database.

    Don't forget to change DATABASE and TABLE to the actual database and table your videos are stored in.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!