Display image only once when variable true one or more times

Hi

I am new to php with mysql and have developed a code element that queries a record set of images. The images that are associated with my user are flagged as different image types and on my web page I want to display a flag just once if the image type is present one or more times in the record set. At the moment if I use the following code the flag appears as many times as the image type appears in the record set. Can someone advise how I limit the echo statement to be applied once only?

if
($image_type==6)
{
echo “<a href=\“form2.php?pid=$itemID\”><img src=\“images/flag.png\” width=\“120\” height=\“20\” border=\“0\” /></a><br />”;
}

Many thanks

Set a condition flag when the image is displayed and, if set, don’t display the image:

if ($image_type==6 AND
    !isset($imageFlag)) {
    echo "<a href=\\"form2.php?pid=$itemID\\"><img src=\\"images/flag.png\\" width=\\"120\\" height=\\"20\\" border=\\"0\\" /></a><br />";
    $imageFlag = TRUE;
}

:slight_smile:

Do you have an array of image types? If so try:

$image_type = array(1,2,3,3,6,5,3,6,6);

foreach ($image_type AS $value) {

	if ($value === 6) {
		echo "image<br>";
		break;
	}

}