Jump to content

Dynamic gallery


rtswimmer

Recommended Posts

Ive got an array of files, which are used to create thumbnails.
I only want 12 thumbnails on each page so ive done this:
[code]  $default_dir = "./products/corporate_signs/gallery/images";
    $height = 50;
    $x = 0;   
    $no = 0;  //counts number of files
    $fpp = 12; // files per page
    $thumb = array();
                   
    if(!($dp = opendir($default_dir))) die("Cannot open $dir");
    while($file = readdir($dp)) {
        if($file != '.' && $file != '..' && stristr($file,"jpg")){ $thumbs[$no] = $file; $no++;    }
    }closedir($dp);
    $pages = ceil($no / $fpp); // Sets Page numbers

            echo"<table border=\"0\" cellpadding=\"0\" cellspacing=\"10\">\n";
            switch($id){
                case"1" :
                    for($i=0; $i<12; $i++){
                        if ($x == 0) { echo"\t<tr>\n"; }    $x++;
                        if ($i < $no){ echo"\t\t<td height=\"$height\"><a href=\"?id=1&?pic=$i\"><img src=\"./gen.php?$default_dir/$thumbs[$i]\" border=\"0\"></a></td>\n";}       
                        if ($x == 3){ echo"\t</tr>\n"; $x = 0; }
                    }break;
                case"2" :
                    for($i=12; $i<24; $i++){
                        if ($x == 0) { echo"\t<tr>\n"; }    $x++;
                        if ($i < $no){ echo"\t\t<td height=\"$height\"><a href=\"?id=2&?pic=$i\"><img src=\"./gen.php?$default_dir/$thumbs[$i]\" border=\"0\"></a></td>\n";}       
                        if ($x == 3){ echo"\t</tr>\n"; $x = 0; }
                    }break;
                case"3" :
                    for($i=24; $i<36; $i++){
                        if ($x == 0) { echo"\t<tr>\n"; }    $x++;
                        if ($i < $no){ echo"\t\t<td height=\"$height\"><a href=\"?id=3&?pic=$i\"><img src=\"./gen.php?$default_dir/$thumbs[$i]\" border=\"0\"></a></td>\n";}       
                        if ($x == 3){ echo"\t</tr>\n"; $x = 0; }
                    }break;
                case"4" :
                    for($i=36; $i<48; $i++){
                        if ($x == 0) { echo"\t<tr>\n"; }    $x++;
                        if ($i < $no){ echo"\t\t<td height=\"$height\"><a href=\"?id=4&?pic=$i\"><img src=\"./gen.php?$default_dir/$thumbs[$i]\" border=\"0\"></a></td>\n";}       
                        if ($x == 3){ echo"\t</tr>\n"; $x = 0; }
                    }break;
                case"5" :
                    for($i=48; $i<60; $i++){
                        if ($x == 0) { echo"\t<tr>\n"; }    $x++;
                        if ($i < $no){ echo"\t\t<td height=\"$height\"><a href=\"?id=5&?pic=$i\"><img src=\"./gen.php?$default_dir/$thumbs[$i]\" border=\"0\"></a></td>\n";}       
                        if ($x == 3){ echo"\t</tr>\n"; $x = 0; }
                    }break;
                case"6" :
                    for($i=60; $i<72; $i++){
                        if ($x == 0) { echo"\t<tr>\n"; }    $x++;
                        if ($i < $no){ echo"\t\t<td height=\"$height\"><a href=\"?id=6&?pic=$i\"><img src=\"./gen.php?$default_dir/$thumbs[$i]\" border=\"0\"></a></td>\n";}       
                        if ($x == 3){ echo"\t</tr>\n"; $x = 0; }
                    }break;
                case"7" :
                    for($i=72; $i<84; $i++){
                        if ($x == 0) { echo"\t<tr>\n"; }    $x++;
                        if ($i < $no){ echo"\t\t<td height=\"$height\"><a href=\"?id=6&?pic=$i\"><img src=\"./gen.php?$default_dir/$thumbs[$i]\" border=\"0\"></a></td>\n";}       
                        if ($x == 3){ echo"\t</tr>\n"; $x = 0; }
                    }break;
                case"8" :
                    for($i=84; $i<96; $i++){
                        if ($x == 0) { echo"\t<tr>\n"; }    $x++;
                        if ($i < $no){ echo"\t\t<td height=\"$height\"><a href=\"?id=6&?pic=$i\"><img src=\"./gen.php?$default_dir/$thumbs[$i]\" border=\"0\"></a></td>\n";}       
                        if ($x == 3){ echo"\t</tr>\n"; $x = 0; }
                    }break;
                default :
                    header("Location: find.php?id=1");
            }echo"</table>";
            for($i=1; $i<=$pages; $i++){ echo"<a href=\"find.php?id=$i\">$i<a>"; }//Outputs Page Links [/code]
(I know its not very tidy or efficient)
But as you can see im only limited to having 96 images, unless i add more case statements.

Also i need help on the main images.. when i click the thumbnail i want the full image shown on the page next to the list of thumbnails.
I cant seem to get it to work tho
[code] switch($pic){
        case"1" :
            echo "<img src=\"$default_dir/$thumbs[1]\" border=\"0\">"; break;
        case"2" :   
            echo "<img src=\"$default_dir/$thumbs[2]\" border=\"0\">"; break;
        default :
            echo "Default"; [/code]
Like before tho i need the case statement to be dynamic so it doesnt matter how many images there are.

Hope that makes sence. Can anyone help me?
Cheers RTSwimmer
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.