treehouse : what would you like to learn today?
Web Design Web Development iOS Development

unexpected T_ELSE

  • Im getting an unexpected T_ELSE and I cant figure it out. Any help appreciated.


    <?php if((get_post_meta($post->ID, "video", true))) { ?>
    <?php echo get_post_meta($post->ID, "video", true); ?>
    <?php } ?>

    <?php else if((get_post_meta($post->ID, "image", true))) { ?>
    <?php
    $images = array(
    'example.jpg',
    'example.jpg',
    'example.jpg',
    );
    $image = $images[array_rand($images)];
    $output = "<img src=\"http://testsite.com/images/random/&quot; . $image . "\" />";
    echo $output;
    ?>
    <?php } ?>
  • $image = $images[array_rand($images)];

    only needs to be

    $image = array_rand($images);
  • still getting same error.
  • Is this the only code? It seems like your if/else statement is being broken. Is there additional code or hidden characters between the close of the if and the start of the else if statement?

    Can you remove the php tags and seemingly blank line that separate them so you end up with } else if { to see if that fixes it?
  • Other then some divs for styling. That is it. and I tried you suggestion on the $image, but it did not work. Thanks for taking the time to look at it. For now, I just changed the "else if" to an "if".
  • That's because I'm pretty sure it's 'elseif', not 'else if'. I'm a PHP noob, though!
  • You would be correct unless you use curly brackets which I did. But elseif is the correct format. :)

    What I read