Atif Shabeer
Atif Shabeer

Reputation: 167

Show url only if value is present

Goal:

Instead of showing simple YES or NO.

If value is found in record, show hyperlink with that value or else show text "No"

How to modify below code for this purpose:

<?php echo $row_RecordsetContacts['propertyFile'] ? '<strong>Yes</strong></br>' : 'No</br>'; ?>
<a href="propfiles/<?php echo $row_RecordsetContacts['propertyFile']; ?>">View</a>

</td>

Upvotes: 0

Views: 47

Answers (2)

oreopot
oreopot

Reputation: 3450

Try the following code:

<?php 
    $prop = $row_RecordsetContacts['propertyFile'];
    if(empty($prop)) {
        echo "No";
    } else {
        echo "<a href='propfiles/$prop'>View</a>";
    }
?>

Upvotes: 1

user1597430
user1597430

Reputation: 1146

<?php

$file = $row_RecordsetContacts['propertyFile']; # for readability only 

if ($file)
{
    ?><a href="propfiles/<?= $file ?>">View</a><?php
}
else
{
    ?>No<?php
}

I also suggest to avoid mixing echo and HTML markup. In 99% cases it makes the code better for understanding.

Upvotes: 1

Related Questions