PCHomepage
Programmer
I created a function for presenting images from a database (MySQL) and it is working after a fashion but I can't get the loop to work quite right as I suspect it needs a second loop inside that I am unsure how to do. Any help is much appreciated.
$ImageIDs is an array of integer values; $ImageCaptions is an array of text values and the other values are not arrays. Not all $ImagesIDs have a matching $ImageCaptions value. In other words, not all images have captions and that might be a clue to where it is failing as it is giving only a single image when there should be up to three.
Thank you.
$ImageIDs is an array of integer values; $ImageCaptions is an array of text values and the other values are not arrays. Not all $ImagesIDs have a matching $ImageCaptions value. In other words, not all images have captions and that might be a clue to where it is failing as it is giving only a single image when there should be up to three.
Code:
function ShowImage($ImageIDs, $ImageCaptions, $ImageType, $Alignment, $Thumbnail) {
$OpenImage = ($Thumbnail == 1) ? "<div class=\"ListThumb\">":"<div class=\"PhotoBox\">";
$ShowCaption = "<div class=\"ImageCaption\">";
$FullDomain = "[URL unfurl="true"]http://".$_SERVER[/URL]['HTTP_HOST'];
$LocalPath = SitePath("Viewers");
$ShowImage = "<img src=\"".$LocalPath."show_image.php?ID=";
$count = count($ImageIDs);
for ($i = 0; $i < $count; $i++) :
$ImageID = $ImageIDs[$i];
$ImageCaption = (isset($ImageCaptions[$i])) ? $ImageCaptions[$i]:"";
$ImageCaption = ($ImageCaption && $Thumbnail == 0) ? $ShowCaption.$ImageCaption."</div>\n":"";
$AltText = ($Thumbnail == 1 && $ImageCaption) ? " alt=\"".$ImageCaption."\"":"";
// Overwrites $ImageType for random images
if ($ImageID == "10000" && $Thumbnail == 0) :
$ImageType = "10&Rand=1";
elseif ($ImageID == "10000" && $Thumbnail == 1) :
$ImageType = "11&Rand=1";
endif;
// Get image height and width parameters
// NOTE: $ImageSize IS PRODUCING AN ARRAY RATHER THAN THE NEEDED VALUES
$ImageSize = ($ImageID) ? list($attr) = getimagesize($FullDomain.$LocalPath."show_image.php?ID=$ImageID&Type=$ImageType"):"";
$ImageSize = $ImageSize[3];
if ($Alignment == 1) : // Show images horizontally side-by-side
$Images = ($ImageID) ? "$OpenImage$ShowImage$ImageID&Type=$ImageType\" $ImageSize$AltText>":"";
$Images .= ($ImageCaption) ? "$ImageCaption":"";
$Images .= "</div>";
else : // Show images vertically above one another
$Images = ($ImageID) ? "$OpenImage$ShowImage$ImageID&Type=$ImageType\" $ImageSize$AltText>$ImageCaption</div>\n":"";
endif;
return $Images;
endfor;
}
Thank you.