Hi guys, I ran into a coding problem. I want to show a button only if my $status variable changes to COMPLETE. I don’t know how to do this. Can anyone help me? Here’s what I’m working on:-
<?php echo $status; ?>
<button name="donwloadbtn" href="www.myweb.com/myfile.jpg" download style="visibility: hidden">
<i class="fa fa-download" aria-hidden="true"></i>
Download</button>
I want if $status == COMPLETE then show $downloadbtn else hide $downloadbtn
<?php
if ($status == 'COMPLETE'){
echo 'Your button code here';
}
You mean like this?
<?php if ($status == 'COMPLETE'){
echo '<-button type="button" name="donwloadbtn" href="www.myweb.com/myfile.jpg" download style="visibility: hidden"><-i class="fa fa-download" aria-hidden="true"></-i> Download</-button>';
}
SamA74
February 7, 2019, 8:30pm
4
pmndela:
You mean like this?
Yes that’s one way, alternatively it can be done like this:-
<?php if ($status == 'COMPLETE') : ?>
<button name="donwloadbtn" href="www.myweb.com/myfile.jpg" download style="visibility: hidden">
<i class="fa fa-download" aria-hidden="true"></i>
Download</button>
<?php endif ?>
Here there is no echo
just normal html because you exit the php tags, but the html only shows if the if
condition that encloses it is true
.
Etiher stye may be used depending on preference or where it’s used.
1 Like
Thanks. It worked smoothly.
I prefer changing the CSS class parameters and passing .hide {display: none;}
<?php
$hide=" "; // default visible
if ($status == 'COMPLETE') :
$hide="hide";
?>
<button
class="<?= $hide ?>"
name="donwloadbtn"
href="www.myweb.com/myfile.jpg"
>
<i class="fa fa-download" aria-hidden="true"></i>
Download
</button>
<?php endif ?>
system
Closed
May 10, 2019, 5:27am
7
This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.