mr john
mr john

Reputation: 5

if statement to show image when variable value is higher then 0

I have this few line of codes to show a 'badge'. If a user has earned one badge I manually put the number in the database column idea_badge in the user profile table.

So in my view I have these lines of code to show the amount of badges:

<a style="font-weight:bold; font-family: Roboto-Black!important; ">
IDEA BADGES:&nbsp;</a>
<?= $user_info['idea_badge']?>

This works just fine.

Now I want to echo the badge image. I thought I can make it like this: if the number in the database is higher then 0 echo the src...

So for that I made this piece of code:

<?php
    $idea_badge = ['idea_badge'];
    if ($idea_badge > 0) {
       print '<img style="width: 30px; height:30px;" src="http://mywebsite.com/photo/new/badge.svg" border=0>'; 
    }

?>

I don't get any errors on my view. But it seems like it only prints the image and doesn't do anything with the if statement.

Can you help me make this statement working?

Upvotes: 1

Views: 96

Answers (1)

Fahmi B.
Fahmi B.

Reputation: 798

the error is here

   $idea_badge = ['idea_badge'];

because $idea_badge always true then

 $idea_badge > 0 // is true

you have put

 $user_info['idea_badge']

Upvotes: 1

Related Questions