Jump to content

Archived

This topic is now archived and is closed to further replies.

scottchr

PHP hyperlink

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.