Jump to content


Photo

PHP hyperlink


  • Please log in to reply
3 replies to this topic

#1 scottchr

scottchr
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 19 July 2006 - 04:51 AM

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?

#2 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 19 July 2006 - 05:06 AM

show us your wild loop and select statement ok.
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#3 akitchin

akitchin
  • Staff Alumni
  • Advanced Member
  • 2,516 posts
  • LocationCalgary, AB, Canada

Posted 19 July 2006 - 05:14 AM

try this (you're already within PHP tags when echoing the link):

if ($row_staffbydepartment['webpage'] == '')
{
echo 'Website';
}
else
{
echo "<a href=\"{$row_staffbydepartment['webpage']}\">Website</a>";
}
?>

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.

#4 scottchr

scottchr
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 19 July 2006 - 02:01 PM

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.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users