SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    Apr 2013
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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

  2. #2
    SitePoint Evangelist captainccs's Avatar
    Join Date
    Mar 2004
    Location
    Caracas, Venezuela
    Posts
    516
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Set a condition flag when the image is displayed and, if set, don't display the image:
    PHP Code:
    if ($image_type==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;

    Denny Schlesinger
    web services

  3. #3
    SitePoint Addict Banana Man's Avatar
    Join Date
    Dec 2005
    Posts
    391
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Do you have an array of image types? If so try:

    Code:
    $image_type = array(1,2,3,3,6,5,3,6,6);
    
    foreach ($image_type AS $value) {
    
    	if ($value === 6) {
    		echo "image<br>";
    		break;
    	}
    
    }


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •