【问题标题】:PHP displaying different information on the same page using buttons? [closed]PHP使用按钮在同一页面上显示不同的信息? [关闭]
【发布时间】:2014-03-03 18:18:17
【问题描述】:

尝试在我的 PHP 网站上列出一个视频系列,虽然我有 3 个系列,而不是创建 3 个不同的网页,有一种方法可以在 1 个页面的底部添加 3 个按钮,例如:

(系列 1)(系列 2)(系列 3)

系列 1 已经在下面列出,但是当用户单击系列 2 或系列 3 时,它不会更改网页,而是在下面列出所选系列而不是系列 1?

我在想这可能与“INCLUDE:”代码有关?但是对这些东西很陌生?谢谢!

P.S:尽量保持简单,越容易越好。

【问题讨论】:

    标签: php list video hyperlink series


    【解决方案1】:

    您可以使用链接将数据传递到 URL,然后在 $_GET 数组中捕获选择。显然 thispage.php 需要更改,如果您真的想要按钮,可以更改一些 html。但想法是这样的:

    echo '
        <a href="thispage.php?series=1">SERIES 1</a>
        <a href="thispage.php?series=2">SERIES 2</a>
        <a href="thispage.php?series=3">SERIES 3</a>
    ';
    
    if (isset($_GET['series'])) {
        $series = $_GET['series'];
    } else {//if there is no choice, display series 1
        $series = 1; 
    }
    
    switch($series) {
        case 1:
            //display series 1
            //e.g. echo...
        break;
    
        case 2:
            //display series 1
        break;
    
        case 3:
            //display series 1
        break;
    
        default:
        break;
    }
    

    【讨论】:

    • 这看起来是最简单的方法,我在页面中输入了代码,虽然它显示了第一个系列,但是当我单击其他链接时,它直接将我带到顶部页面并没有改变?
    • 我在那里移动得太快了 - 应该是 $_GET 数组。答案已编辑。
    【解决方案2】:

    最简单的方法是在“x”div 中渲染所有视频;每个都有一个唯一的 ID。然后使用 javascript 显示/隐藏单击的任何系列。大致如下:

    <button id="one" class="videoSeries" value="ViewSeries One" />
    <button id="two" class="videoSeries" value="View Series Two" />
    
    
    <div class="videoContainer" id="videoSeriesOne">
        <ul>
        <?php
            $videos = get_videos(seriesOne); // Get all videos for a given series.
            for($i=0; i<$videos.length; i++;) { // Loop through videos & create the links
                echo'<li><a href="'.$video[i]['video_href'}.'">'.$video[i]['video_title'].'<a></li>';
            }
        ?>
        </ul>
    </div>
    
    <div class="videoContainer" id="videoSeriesTwo">
        <ul>
        <?php
            $videos = get_videos(seriesOne); // Get all videos for a given series.
            for($i=0; i<$videos.length; i++;) { // Loop through videos & create the links
                echo'<li><a href="'.$video[i]['video_href'}.'">'.$video[i]['video_title'].'<a></li>';
            }
        ?>
        </ul>
    </div>
    
    ... and so on
    

    你的 javascript 看起来像这样(使用 jQuery):

    $('.videoSeries').on('click', function(event) {
        var seriesToShow = $(this).attr('id').val();
        $('.videoContainer').hide();
        switch(seriesToShow) {
         case 'one':
         $('#videoSeriesOne').show();
         break;
        } 
    }
    

    到目前为止,这并不是最有效的方法,但它非常简单直接。您可能需要稍微调整方法,但这应该可以帮助您。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-03-10
      • 1970-01-01
      • 1970-01-01
      • 2012-04-08
      • 1970-01-01
      • 1970-01-01
      • 2016-10-03
      • 1970-01-01
      相关资源
      最近更新 更多