Jump to content
GrahamMercer

Help with Conditional Statement please

Recommended Posts

Hi and first of all thanks to everyone here that takes the time to help out newbies such as myself. :) I have a conditional IF statement that allows me to add a link to a piece of text if that record has a website, but I would like to also be able to display the text without the link if there is no website associated with the record.The code that I am currently using is

 <?php if($row_RSsales['website']!='') { ?><a href="<?php echo $row_RSsales['website']; ?>" target="_blank"><?php echo $row_RSsales['name']; ?></a><?php } ?>

The trouble with this is that if a particular record does not have a website then the code does not echo the business name. I would like to include an ELSE statement with the IF statement so that when a record does not have a website entry the business name is still echoed, but not hyperlinked.I have been fiddling with code but cannot figure out how to do it.

 <?php if($row_RSsales['website']!='') { ?><a href="<?php echo $row_RSsales['website']; ?>" target="_blank"><?php echo $row_RSsales['name']; ?></a>;else <?php echo $row_RSsales['name']; ?><?php } ?>

doesn't work and I am not sure how to solve it.Any suggestions would be greatly appreciated!thanks,Graham :)

Share this post


Link to post
Share on other sites
<?php  if ($row_RSsales['website'] == '')  {  echo '<a href="'	 . $row_RSsales['website']	 . '" target="_blank">'	 . $row_RSsales['name']	 . '</a>';  }  else  {  echo $row_RSsales['name'];  }?>

that should do it.love,jason

Share this post


Link to post
Share on other sites
<?php  if ($row_RSsales['website'] == '')  {  echo '<a href="'	 . $row_RSsales['website']	 . '" target="_blank">'	 . $row_RSsales['name']	 . '</a>';  }  else  {  echo $row_RSsales['name'];  }?>

that should do it.love,jason

you changed the condition here from != to == :
if ($row_RSsales['website'] == '')

it should be like this:

if ($row_RSsales['website'] != '')

Share this post


Link to post
Share on other sites

You guys are awesome!Thanks so much for the code (and correction), your help is greatly appreciated.Talk about helpful, less than an hour from when I posted my question and the problem is solved!Cheers,Graham

Share this post


Link to post
Share on other sites

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.   Paste as plain text instead

  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.

Loading...

×
×
  • Create New...