2

I have a database driven website. There is a basic template that is the format for each page. There are various parts that need to change for each different page. One line for an example is this.

 <link rel="canonical" href="http://mywebsite.com/details.php?id=1" />

I changed the line code to this and stills it works fine and does exactly what I wanted it to do.

<link rel="canonical" href="<?php echo "$record->canonical";?>" />

The problem I am having is, when the cell is empty I am printing this line which is not need if the quotes are blank. How can I remove this line when the cell in my database is empty?

<link rel="canonical" href="" />
1
  • could you give more detail about $record->canonical can you share the page code ? Commented Dec 13, 2015 at 1:47

2 Answers 2

4
<?php if ($record->canonical != ""): ?>
<link rel="canonical" href="<?php echo $record->canonical ?>" />
<?php endif ?>
Sign up to request clarification or add additional context in comments.

Comments

1
<?php 
echo($record->canonical != "" ? $record->canonical : '');
?>

Which is the same as if $record->canonical is not "" (after the ?-sign) echo it, otherwise (after the :-sign) echo nothing ( '' ).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.