Jeremy Person
Jeremy Person

Reputation: 169

PHP/MYSQL Show Image If In Database

I have a while loop that is going through and displaying an RSS icon for websites from database values. The while loop is working well but right now it is displaying an RSS icon for every site. I only want to display an icon if there is a RSS URL value in the database. Below is what I have coded thus far.

The error message I am receiving is: Parse error: syntax error, unexpected T_STRING, expecting ',' or ';'

I believe I have a syntax error but am still learning so apologize if this is basic but I am again still learning. Thank you very much for your help.

    <td><div class="centerit"><a href="
    <?php if (isset($r['rssURL'])) { 
    echo $r['rssURL'] target='_blank'><img src='images/rssIcon.gif'></a>;
    } 
    ?>"</div></td>

Upvotes: 0

Views: 350

Answers (2)

Phil
Phil

Reputation: 164760

Your PHP code is getting mixed incorrectly with the markup. Try the following

<td>
    <div class="centerit">
        <?php if (isset($r['rssURL'])) : ?>
        <a href="<?php echo $r['rssURL'] ?>" target="_blank">
             <img src="images/rssIcon.gif">
         </a>
        <?php endif ?>
    </div>
</td>

Upvotes: 3

zerkms
zerkms

Reputation: 254916

echo $r['rssURL'] target='_blank'><img src='images/rssIcon.gif'></a>;

This is invalid. I think you meant something like

<td><div class="centerit"><a href="
<?php if (isset($r['rssURL'])) { 
echo $r['rssURL'];
} 
?>" target='_blank'><img src='images/rssIcon.gif'></a></div></td>

or even:

<td>
    <div class="centerit">
        <a href="<?php echo isset($r['rssURL']) ? $r['rssURL'] : ''; ?>" target='_blank'><img src='images/rssIcon.gif'></a>
    </div>
</td>

Upvotes: 1

Related Questions