Q:

Display image if field is true

I have a table called user_badges and a field called badge1 with the default value written "locked" when a user unlocks the badge the field is updated to "unlocked"
What I want is the script to check the value in the field badge 1 in the table  WHERE $username = $_SESSION['username']; and display the image of the badge located in a folder on my site.
I have an idea on how to go about it but not sure how to fully execute this. 
//Connect to database
<?php
$connect = mysql_connect("host","username","password");
mysql_select_db("database_name");
?>

if field (field_name) from table (table_name) value= unlocked
echo/display image from (images/badges/fanaticbadge.png)

else echo/display (images/badges/locked.png) 

Is this possible? Thanks for any assistance !

A:

$q = "SELECT badge1 FROM user_badges WHERE username='{$_SESSION['username']}' LIMIT 1";
$r = mysql_query($q);
$row = mysql_fetch_assoc($r);
$badge1 = $row['badge1'];

if($badge1 == "unlocked") {
 print "image if user has unlocked the badge";
  } else {
 print "image if user hasn't unlocked the badge";
}

