Reputation: 70
I have these bits here that will display a google map link for me. How can I wrap this in some sort of if statemnt that will check to see if there is ANY data in $event['where']
. I don't want the link to display when there is no data.
<a title="See on Map" target="_blank" href="http://maps.google.com/maps?q=<?php echo $event['where']; ?>">See on map</a>
Upvotes: 2
Views: 4342
Reputation: 7946
The following will not show the link if $event['where']
is not set, is null, is blank (""
), is false
or is 0
- I think it is what you want:
<?php
if (!empty($event['where'])) {
?>
<a title="See on Map" target="_blank" href="http://maps.google.com/maps?q=<?php echo $event['where']; ?>">See on map</a>
<?php
}
?>
Upvotes: 1
Reputation: 26177
Well isset()
will determine if a variable/object is set and is not null
if(isset($event['where'])){
//...
}
http://php.net/manual/en/function.isset.php
Upvotes: 1
Reputation: 4931
<?php if(!empty($event)){ ?> <a title="See on Map" target="_blank" href="http://maps.google.com/maps?q=<?php echo $event['where']; ?>">See on map</a> <?php } ?>
Upvotes: 3
Reputation: 17139
Try this:
<?php echo (!empty($event['where'])) ? $event['where'] : ""; ?>
Upvotes: 1