Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Regular Coder
    Join Date
    Jun 2012
    Posts
    116
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Multiple videos not wanted

    http://mroldies.net/MASTER1.html

    The first two items are linked to an external page on my site, which in turn, calls up a slide-in panel which displays a video.
    However, it is currently displaying both videos.
    I only want one per link.
    How do I correct that?

    PHP Code:
    $number=$GET_["number"];

    if (
    $number=A1){ echo '<iframe width="640" height="360" src="http://www.youtube.com/embed/EflCFJ5F0v4?feature=player_detailpage" frameborder="0" allowfullscreen></iframe>' ;}
    if (
    $number=A2) { echo '<iframe width="640" height="360" src="http://www.youtube.com/embed/5gllzuBsGhs?feature=player_detailpage" frameborder="0" allowfullscreen></iframe>';} 

  • #2
    Regular Coder
    Join Date
    Sep 2011
    Posts
    213
    Thanks
    15
    Thanked 5 Times in 5 Posts
    Well for starters your comparison is incorrect in two ways. You are setting $number on both lines, and you are setting them to invalid values. The A1 and A2 should be wrapped in quotes (unless they are values defined with the define() function) to indicate it is a string. For comparing them, you are required to use two equal signs.

    For more information on the comparison, check out php.net's explination on it

  • #3
    Regular Coder
    Join Date
    Jun 2012
    Posts
    116
    Thanks
    0
    Thanked 0 Times in 0 Posts
    well for now my thinking is to code the links to an array, then echo the array.
    But it's showing a parse error in $list[1].
    Keep forgetting the ;.
    Now it just shows a blank page.

    PHP Code:
    <?php


    $list
    [0]="no value"
    $list[1]='<iframe width="640" height="360" src="http://www.youtube.com/embed/EflCFJ5F0v4?feature=player_detailpage" frameborder="0" allowfullscreen></iframe>'
    $list[2)='<iframe width="640" height="360" src="http://www.youtube.com/embed/5gllzuBsGhs?feature=player_detailpage" frameborder="0" allowfullscreen></iframe>'

    $number=$GET_["number"];

    echo 
    $list[$number]

    ?>
    Last edited by Suwannee_guy; 04-09-2013 at 04:15 AM.

  • #4
    Regular Coder
    Join Date
    Jun 2012
    Posts
    116
    Thanks
    0
    Thanked 0 Times in 0 Posts
    What can I do so that I don't have to use a literal number as I do here?
    That is, replace the if's with echo $number[value];



    PHP Code:

    $list
    [0]="";
    $list[1]='<iframe width="480" height="270" src="http://www.youtube.com/embed/EflCFJ5F0v4?feature=player_detailpage" frameborder="0" allowfullscreen></iframe>';
    $list[2]='<iframe width="480" height="270" src="http://www.youtube.com/embed/5gllzuBsGhs?feature=player_detailpage" frameborder="0" allowfullscreen></iframe>';
    $list[3]='<iframe width="480" height="270" src="http://www.youtube.com/embed/XC9jjsmXe38?feature=player_detailpage" frameborder="0" allowfullscreen></iframe>';



    $number=$_GET["number"];

    if (
    $number==1) echo $list[1];
    if (
    $number==2) echo $list[2];
    if (
    $number==3) echo $list[3]; 

  • #5
    Regular Coder
    Join Date
    Sep 2011
    Posts
    213
    Thanks
    15
    Thanked 5 Times in 5 Posts
    Try this:

    PHP Code:
    $list = array();
    $list[1]='<iframe width="480" height="270" src="http://www.youtube.com/embed/EflCFJ5F0v4?feature=player_detailpage" frameborder="0" allowfullscreen></iframe>';
    $list[2]='<iframe width="480" height="270" src="http://www.youtube.com/embed/5gllzuBsGhs?feature=player_detailpage" frameborder="0" allowfullscreen></iframe>';
    $list[3]='<iframe width="480" height="270" src="http://www.youtube.com/embed/XC9jjsmXe38?feature=player_detailpage" frameborder="0" allowfullscreen></iframe>';


    $number=$_GET["number"];
    $number = (Int)$number//Adding this

    echo $list[$number]; 
    Theoretically you could add it to the line where it's set to the $_GET variable, but I prefer to keep that line separate from the rest. You should be able to do it if you prefer to save an extra line.

    You should also think about adding a filter in case the number doesn't exist or something goes wrong. Perhaps something like this:

    PHP Code:
    if(key_exists($number$list))
        echo 
    $list[$number];
    else
        echo 
    '<p>Video not found.</p>'

  • #6
    Regular Coder
    Join Date
    Jun 2012
    Posts
    116
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks.
    Just what I needed. Works perfectly.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •