A: 

Try something like:

    <?php
    if($row_rsemalpha['URL'] != NULL){
        $buttonCode = '<a href="http://'.$row_rsemalpha['URL'].'" target ="_blank"><img src="web_button_on.gif" alt="Website" border="0" height="18" width="103"></a>';  
}else{
    $buttonCode = '<img src="web_button_off.gif" alt="No Website Available" height="18" width="103"/>';
}
echo $buttonCode;
?>
Jorge
Yet another way to skin the cat! I like this one for neatness.
Diane
+1  A: 

I'm not entirely sure about how PHP handles IF statements when going out of the PHP mode, but essentially your problem is the lack of curly braces. Both buttons are outputted because PHP doesn't recognize the exit from PHP mode as a statement that's related to the IF clause. Just wrap the contents of the if clause into curly braces and your code should work fine.

For example, this should work:

<?php
if($row_rsmemalpha['URL'] != NULL)
{
?><a
 href="http://&lt;?php echo ($row_rsmemalpha['URL']);?>"><target
 ="_blank"><img src="web_button_on.gif"
 alt="Website" border="0" height="18" width="103" /></target></a>

<?php
}
if($row_rsmemalpha['URL'] == NULL)
{
    echo "<img src=\"web_button_off.gif\" alt=\"No Website Available\" height=\"18\" width=\"103\" />";
}
?>
Rithiur
Beautimous! Works perfectly. Thank you!
Diane
+1  A: 

I would recommend using empty() and !empty() for your checks.

if(!empty($row_rsmemalpha['URL'])) { /* etc */
bigstylee
A: 

Your logic is ok, I think it's just written sloppy. I recommend you try to write your code a little cleaner and you will run into way fewer problems. This is your code cleaned up:

$url = $row_rsmemalpha['URL'];

if($url != NULL){
    echo '<a href="http://'.$url.'"&gt;
            <target ="_blank"><img src="web_button_on.gif" alt="Website" border="0" height="18" width="103" />
            </target>
        </a>';
}

if($url == NULL){
    echo '
        <img src="web_button_off.gif" alt="No Website Available" height="18" width="103" />';
}

Now you can see that this should be an if/else, to make sure that only one of them gets output, and then you only have to fiddle with one test to see if the url is there.

Syntax Error
I have never used PHP and the last code writing I ever did was in 9th grade using BASIC on a TRS 80! Similar, but...well yeah. Thanks for the example--that IS much clearer.
Diane
A: 

here is my approach :)

<?php if($row_rsmemalpha['URL']): ?>
  <a href="http://&lt;?php echo ($row_rsmemalpha['URL']);?>" target ="_blank">
    <img src="web_button_on.gif" alt="Website" border="0" height="18" width="103"/>
  </a>
<?php else: ?>
  <img src="web_button_off.gif" alt="No Website Available" height="18" width="103" />";
<?php endif ?>

I'd recommend to shorten $row_rsmemalpha variable name and use short open tags to make this template look real neat:

<? if($row['URL']): ?>
  <a href="<?=$row['URL']);?>" target ="_blank">
    <img src="web_button_on.gif" alt="Website" border="0" height="18" width="103"/>
  </a>
<? else: ?>
  <img src="web_button_off.gif" alt="No Website Available" height="18" width="103" />";
<? endif ?>
Col. Shrapnel
I had considered shortening that variable name, but figured that was something that could be done once I had the dang thing working! Maybe I'll clean up the code next.I had seen those <? tags: ?> in one place and wondered if that was another way of telling php what to do. None of the tutorials I looked at used that form, at least not in the simple examples I was studying.Thanks, Col.
Diane