I’ve got a webpage that I’m working on where you click on a letter or category and it displays records matching that query from a database. One of the things I want to display is a hyperlinked button that says “Website” if the database record contains a URL in the ‘URL’ field, and if there is no value in that field, it will display a greyed out version of that button.
I tried using an if…else statement, but was absolutely unable to get the syntax correct trying to get php to call up the ‘URL’ value in the middle of an “echo ”
So here’s what I did:
<?php if($row_rsmemalpha['URL'] != NULL) ?><a
href="http://<?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\" />";
?>
If there is a URL available it shows the button properly. But if there isn’t a URL in the database it shows both buttons.
I have spent a few days studying examples and tutorials on the web, but haven’t found too much that helps. The buttons were completely non-functional when I started, so I’m pretty proud of getting this far with it! I’ve just run out of time and patience for more trial-and-error experimenting.
Any help is appreciated…
Diane
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: