vendredi 31 juillet 2015

Display youtube iframe if url stored in mySQL

I created a form where we can register youtube embed url in a post. I'd like to display the iframe only if an url has been register for this post.

I made this code to display the report information :

<?php

$req = $db->query('SELECT id, title, author, category, date_event, country, city, content, tag, youtube FROM report ORDER BY date_creation DESC LIMIT 0, 10');

while ($data = $req->fetch())
{
?>

<div class="news">
      <h3><?php echo htmlspecialchars($data['title']); ?></h3>
      <p>Author: <?php echo htmlspecialchars($data['author']); ?></p>
            <p>Category : <?php echo htmlspecialchars($data['category']); ?></p>
            <p>Date of the event : <?php echo htmlspecialchars($data['date_event']); ?></p>
            <p>Country : <?php echo htmlspecialchars($data['country']); ?></p>
            <p>City : <?php echo htmlspecialchars($data['city']); ?></p>
            <p class="display_list"><?php echo html_entity_decode($data['content'], ENT_HTML5 , 'UTF-8'); ?></p>
            <p>Tag : <?php echo htmlspecialchars($data['tag']); ?></p>
            <p>

            <?php
$youtube=1;

if($youtube==1){
    echo "<p>display iframe</p>";
}else{
{
        echo "<p>don't display iframe</p>";
    }
}        
?>
</p>

Actually all the posts are displayed with the "display iframe" message.

The condition statement for $youtube variable is certainly not right but I can't figure out the issue.

Aucun commentaire:

Enregistrer un commentaire