0

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>

2 Answers 2

3

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>
Sign up to request clarification or add additional context in comments.

1 Comment

+1 - I wrote the same answer until I deleted it after seeing this one come in a bit earlier.
1
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>

3 Comments

This should be correct. Without the missing concatenation operator the interpreter doesn't know what to do with the remainder of the line of code.
I think he wants to not display the anchor and link if there's no URL, not just make the anchor not go anywhere
@Phil Brown: if so - he need to learn how to ask questions then.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.