Jump to content

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?
Link to comment
https://forums.phpfreaks.com/topic/15008-php-hyperlink/
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.
Link to comment
https://forums.phpfreaks.com/topic/15008-php-hyperlink/#findComment-60354
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.