php image gallery ... image array & urls - help please

cjamesblanton

New Member
Hello everyone. I've been struggling with coding an image gallery for my art portfolio for the past few days. I thought that maybe someone here could provide me with a simple solution. Here's what I have so far: http://james-blanton.com/version2/ ... take a look at the 4 thumbnails.

Right now, this code simply reads images from an array and outputs them into div areas until the loop reaches the end of the array.

All I want to do is create links that are assigned to each image in the array. I'm not exactly sure if I'm thinking along the right lines or not, but I believe that this could be done with some sort of parallel array? I'm terrible with programming. My guess is that many users here could provide me with the exact answer in 5 minutes.

PHP:
<?php
		
         //a list of support file types to allow in the gallery
         $allowed_filetypes = array('.jpg','.gif','.png','.bmp'); 
                            
        
        function testFUNC (){
        $my_images = array ("http://www.webdesignforum.com/images/image1.jpg", "http://www.webdesignforum.com/images/image2.jpg", "http://www.webdesignforum.com/images/image3.jpg", "http://www.webdesignforum.com/images/image4.jpg");
        $currents = current($my_images);
        $totals = count($my_images);
        $i=0;
		
        while ($i< $totals) {
                echo "<div class='box'>";
                    echo '<img src="'.$my_images[$i].'" /></img>'; 
                    echo '</div>';
            $i++;
        }
        }
        testFUNC();
		
        ?>
 
Last edited:

JakClark

New Member
Simplest of the simplest, but:

PHP:
<?php 
         
         //a list of support file types to allow in the gallery 
         $allowed_filetypes = array('.jpg','.gif','.png','.bmp');  
                             
         
        function testFUNC (){ 
        $my_images = array ("http://lorempixel.com/75/74/sports/", "http://lorempixel.com/75/74/food/", "http://lorempixel.com/75/74/abstract/", "http://lorempixel.com/75/74/nightlife/"); 
        $my_image_links = array ("http://google.com/", "http://bing.com/", "http://ask.com/", "http://yahoo.com/");
        $currents = current($my_images); 
        $totals = count($my_images); 
        $i=0;
        $l=0; 
         
        while ($i< $totals) { 
                echo "<div class='box'>"; 
                    echo '<a style="background-image:url('.$my_images[$i].');width:75px;height:74px;float:left" href="'.$my_image_links[$l].'" /></a>';  
                    echo '</div>'; 
            $i++;
            $l++;
        } 
        } 
        testFUNC(); 
         
        ?>

Didn't know if this was the approach you was going for - but it's *a* method. Did you want all values in one array or?

EDIT: This is closer to your code - I dunno why I altered it in the first place. xD

PHP:
<?php 
         
         //a list of support file types to allow in the gallery 
         $allowed_filetypes = array('.jpg','.gif','.png','.bmp');  
                             
         
        function testFUNC (){ 
        $my_images = array ("http://lorempixel.com/75/74/sports/", "http://lorempixel.com/75/74/food/", "http://lorempixel.com/75/74/abstract/", "http://lorempixel.com/75/74/nightlife/"); 
        $my_image_links = array ("http://google.com/", "http://bing.com/", "http://ask.com/", "http://yahoo.com/");
        $currents = current($my_images); 
        $totals = count($my_images); 
        $i=0;
        $l=0; 
         
        while ($i< $totals) { 
                echo "<div class='box'>";
                    echo '<a href="'.$my_image_links[$l].'">';
                        echo '<img src="'.$my_images[$i].'" /></img>';  
                    echo '</a>';
                echo '</div>'; 
            $l++;
            $i++;
        } 
        } 
        testFUNC(); 
         
        ?>
 
Last edited:
Top