Jump to content

Help with Conditional Statement please


GrahamMercer

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 :)

Link to comment
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

Link to comment
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'] != '')

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...