mercredi 29 janvier 2020

PHP If Statement last value duplicating

I have a php if statement. For some reason it is duplicating multiple times the last statement. Also, I can't add anything after this section. It only multiplies the last statement if I add something after the if statement. I start the new statement with echo ' '; however, it still adds the last statement into the new section.

<?php
if (mysqli_num_rows($result) > 0) {
    // output data of each row
    while($row = mysqli_fetch_assoc($result)) {

        echo '<div class="object">';        
        if (empty($row['facebook'])) {
            echo '';
        }
        else {
            echo '<a class="fab fa-facebook" href='.$row['facebook'].' target="_blank">';
        }

        if (empty($row['twitter'])) {
            echo '';
        }
        else {
            echo '<a class="fab fa-twitter" href='.$row['twitter'].' target="_blank">';
        }

        if (empty($row['linkedin'])) {
            echo '';
        }
        else {
            echo '<a class="fab fa-linkedin" href='.$row['linkedin'].' target="_blank">';
        }

        if (empty($row['youtube'])) {
            echo '';
        }
        else {
            echo '<a class="fab fa-youtube" href='.$row['youtube'].' target="_blank">';
        }

        if (empty($row['instagram'])) {
            echo '';
        }
        else {
            echo '<a class="fab fa-instagram" href='.$row['instagram'].' target="_blank">';
        }

        if (empty($row['pinterest'])) {
            echo '';
        }
        else {
            echo '<a class="fab fa-pinterest" href='.$row['pinterest'].' target="_blank">';
        }               
        echo '</div>';          
    }
}

mysqli_close($conn);
?>

Aucun commentaire:

Enregistrer un commentaire