scottchr Posted July 19, 2006 Share Posted July 19, 2006 I've been trying to figure this out for the last 2+ hours and I'm getting desperate. Can someone please help me?I'm trying to show PHP/MYSQL data on a page. One of my fields (webpage) contains URL information. What I need to do is IF the field is empty in the database I want it to just show a blank space but if the field is NOT empty I want it to show a hyperlink using the data from the database. I tried about every variation of the code below that I can think of:if ($row_staffbydepartment['webpage']; == "";) {echo "Website";} else {echo "<a href="<?php echo $row_staffbydepartment['webpage']; ?>">Website</a>";}?>but it didn't work. Can anyone offer a suggestion? Quote Link to comment https://forums.phpfreaks.com/topic/15008-php-hyperlink/ Share on other sites More sharing options...
redarrow Posted July 19, 2006 Share Posted July 19, 2006 show us your wild loop and select statement ok. Quote Link to comment https://forums.phpfreaks.com/topic/15008-php-hyperlink/#findComment-60353 Share on other sites More sharing options...
akitchin Posted July 19, 2006 Share Posted July 19, 2006 try this (you're already within PHP tags when echoing the link):[code]if ($row_staffbydepartment['webpage'] == ''){echo 'Website';}else{echo "<a href=\"{$row_staffbydepartment['webpage']}\">Website</a>";}?>[/code]you need to escape double quotes when echoing/defining strings that are delimited (surrounded) by double quotes, otherwise PHP thinks you're exiting the echo/definition. second, only statements that are on a line need to have a semicolon. Quote Link to comment https://forums.phpfreaks.com/topic/15008-php-hyperlink/#findComment-60354 Share on other sites More sharing options...
scottchr Posted July 19, 2006 Author Share Posted July 19, 2006 THANKS! It your code worked perfectly.I know ASP.net but I'm trying to teach myself PHP. Thanks for the syntax help. I REALLY appreciate it. Quote Link to comment https://forums.phpfreaks.com/topic/15008-php-hyperlink/#findComment-60464 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.