Jump to content

[SOLVED] Displaying 5 images in a row


Grodo

Recommended Posts

Hello,

Once again I come to the PHP Freaks community for help.  I have spent serveral weeks trying to figure out how to do this. Attached below is code for a function that outputs images in a row. However I am tring to find a way so that it would output 5 images and then drop a line and continue to do this untill all the images have been displayed.  The variable which the output is stored in is named $out (towards the bottom).  The variable $thumb_row is the total number of images that are allowed to be displayed.  Here is an illustration of what I am trying to do the X is an image.

 

XXXXX

XXXXX

XXXXX

XXXXX

 

 

Thank you,

Grodo

 

function my_filmstrip($thumbnail_dir, &$template, $a_images, $currentPic, $thumb_row, $path_to_images) {
    global $path;
    global $auto_url;

    // get size of $a_images array...
    $number_pics = count($a_images);

    // do a little error checking...
    if ($currentPic > $number_pics) $currentPic = 0;
    if ($currentPic < 0) $currentPic = 0;
    if ($thumb_row < 0) $thumb_row = 1;
    if ($thumb_row > $number_pics) $thumb_row = $number_pics;

    if ($currentPic >= $thumb_row) {
        $start = $currentPic - $thumb_row + 1;
    }
    else {
        $start = 0;
    }

    $out = '';
    for ($x = $start; $x < ($start + $thumb_row); $x++ ) {
        $item = preg_split('/;/', rtrim($a_images[$x]), 2);
        $class = $x == $currentPic ? 'thumbnail_center' : 'thumbnail';
	if ($number_pics > 4)

        $out .= "\n<style type='text/css'>.img{opacity:1;filter:alpha(opacity=100)}a:hover img{filter:xray}</style><a href='$path?directory=$path_to_images$auto_url&currentPic=$x' class='thumbnail'><img src='$path_to_images/$thumbnail_dir/".$item[0]."' class='$class'></a>";

}

    $template = str_replace("<THUMBNAIL_ROW>",$out,$template);
}

Link to comment
https://forums.phpfreaks.com/topic/71452-solved-displaying-5-images-in-a-row/
Share on other sites

I have read over through the post but im still confused on how to input that into a variable....  This is what i came up with

	$i = 0;
	if ($i == 0)
		echo "<tr>";
                         echo "Image Goes Here"
	if (++$i == $max_imagerow) {
		echo "</tr>";
		$i=0;
	}

 

what would be the best way to put it into one.

My new code but still no luck someone please help

   for ($x = $start; $x < ($start + $thumb_row); $x++ ) {
        $item = preg_split('/;/', rtrim($a_images[$x]), 2);
        $class = $x == $currentPic ? 'thumbnail_center' : 'thumbnail';
	$out .= "\n<style type='text/css'>.img{opacity:1;filter:alpha(opacity=100)}
	a:hover img{filter:xray}</style>
	<a href='$path?directory=$path_to_images$auto_url&currentPic=$x' class='thumbnail'>
	<img src='$path_to_images/$thumbnail_dir/".$item[0]."' class='$class'></a>";
	for ($check =0; $check < $thumb_row; $check++) {
	if ($check=4)
		$out = $out + "<br>";
	if ($check=
		$out = $out + "<br>";
	}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.