Results 1 to 3 of 3

Thread: Checking for a value & modifying output accordingly with PHP

  1. #1

    Default Checking for a value & modifying output accordingly with PHP

    Hi All,

    Bit of a coding error here - self-taught from messing around with PHP and help I've got from here in the past, so I think I've got into some bad habits and thats what's causing the problem!

    My issue is; at present I've got a SQL database with a list of videos which are all hosted onsite; however I've recently added some videos which are hosted offsite on youtube... What I'd like to do is pull videos from the internal source UNLESS a youtube selection has been made...

    I thought the easiest way to do this would be to add two fields into my database, a value that is yes or no (to see if their is a youtube link) and a field containing the YouTube embed code to be displayed if the value is yes - otherwise the traditional/existing onsite field is served to the user and results in a quicktime being displayed.

    My code looks like this:
    PHP Code:
    PHP Code:
    <?php  

    $video 
    $_GET['video']; 

    ?> 
    <?php 
    $data 
    mysql_query("SELECT * FROM video WHERE ID = '{$video}' ORDER BY added DESC") or die(mysql_error()); 
    mysql_real_escape_string($video); 
    while(
    $info mysql_fetch_array$data )) if ({$info['ytembed']} = yes) {  
    echo 
    "<div class='video-container'>"
    echo 
    "{$info['embedcode']}"
    echo 
    "<div class='video-title'>{$info['title']}</div>"
    echo 
    "<div class='video-subtitle'>{$info['subtitle']}</div>"
    echo 
    "</div>"
    } else { 
    echo 
    "<div class='video-container'>"
    echo 
    "<div class=\"video-js-box\">"
    echo 
    "<video class=\"video-js\" width=\"640\" height=\"360\" controls preload poster=\"../{$info['still']}\"> 
    <source src=\"../
    {$info['qtmobile']}\" type='video/mp4; codecs=\"avc1.42E01E, mp4a.40.2\"' />"
    echo 
    " <object id=\"flash_fallback_1\" class=\"vjs-flash-fallback\" width=\"640\" height=\"360\" type=\"application/x-shockwave-flash\"  
    data=\"http://releases.flowplayer.org/swf/flowplayer-3.2.1.swf\"> 
    <param name=\"movie\" value=\"http://releases.flowplayer.org/swf/flowplayer-3.2.1.swf\" /> 
    <param name=\"allowfullscreen\" value=\"true\" /> 
    <param name=\"flashvars\"  
    value='config={\"playlist\":[\"http://www.website.com/
    {$info['qtmobile']}\", {\"url\": \"http://www.jameshenry.info/{$info['qtmobile']}\",\"autoPlay\":false,\"autoBuffering\":true}]}' /> 
    <img src=\"../
    {$info['still']}\" width=\"640\" height=\"360\" alt=\"Poster Image\"  
    title=\"No video playback capabilities.\" /> 
    </object>"

    echo 
    "</video></div>"
    echo 
    "<div class='video-title'>{$info['title']}</div>"
    echo 
    "<div class='video-subtitle'>{$info['subtitle']}</div>"
    echo 
    "<br>"
    echo 
    "<div class='back'><a href=\"./\">&laquo;back</a></div>"
    echo 
    "</div>"

    ?>
    I'm getting a syntax error on line 37 at the moment, so I'm guessing my error is with this "while($info = mysql_fetch_array( $data )) if ({$info['ytembed']} = yes) { "

    Any help sorting this issue out would be appreciated! Any ideas?

  2. #2
    Join Date
    Feb 2006
    Location
    Florida, USA
    Posts
    1,498

    Default

    PHP Code:
    if ({$info['ytembed']} = yes
    should be
    PHP Code:
    if ($info['ytembed'] == 'yes'
    because you're comparing something (using two equal signs) with a string (quotes). A single equal sign means you're assigning the value to the variable, and without putting quotes around the string you're treating it as a constant so it's trying to look up what "yes" means, and it's probably not defined.

    A variable also shouldn't have brackets around it unless it's being embedded in a string.

    Also, usually you would store a boolean (true/false) in the database for something like this, not a string saying "yes", then you could just go if($info['ytembed']) and by default it would compare it with True.
    Last edited by Basil; 07-22-2011 at 08:04 AM.
    If at first you don't succeed, try reading the instructions.
    semlar.com

  3. #3

    Default

    Basil - Once again massive thanks!

    Sorry for the delayed response, but have got this working and wanted to post a thanks!

Tags for this Thread

Posting Permissions

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