Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Spacing, Colums and pages and sorting array images.

Status
Not open for further replies.

Programz8

Programmer
Mar 27, 2007
33
0
0
US
Hi All,

Can anyone give me some hints on how I can separate the array of images that is produced by the code below. I want to be able to control the spacing between images, the amount of columns and allow for more than one page if there are too many images in the array. I am also interested in created a new field in my database called a type field and that way I would be able to sort items in the array such as a category for cats a category for dogs a category for fish. So that if someone only wanted to view fish they could pull only the fish from the array instead of mandating everything in the array. If anyone could help me out with any of these aspects your help would be greatly appreciated.

<?php

$imageDir = "image_gallery/"; # Location of small versions
$big = "big/"; # Location of big versions (assumed to be a subdir of above)
$text = "text.txt";

$fh=fopen($text, "rb");

while(!feof($fh)) {
$line = fgets($fh);
$image[] = explode(",", $line);
}
echo <<<HTML
<style type="text/css">
.floated {font-family:Verdana, Arial, Helvetica, sans-serif; font-size:9px; color:#000066; margin: 2px; width:100px; height: 150px; background-color:#FEF8E2; float:left; text-align:center;}
</style>

HTML;

foreach ($image as $image){
if (file_exists($imageDir.$image[0])){
echo <<<HTML
<div class="floated">
<a href="{$imageDir}{$big}{$image[0]}">
<img src="{$imageDir}{$image[0]}">
</a><br/>
{$image[1]}
</div>

HTML;
} //end the internal if
} //end the foreach
?>
 
for spacing increase the value for margin

for columns, adjust the value of width.

for paging, see the FAQ section of this forum

for categorisation: this should work, assuming you have added the category field on as the last field of a row
Code:
 if (file_exists($imageDir.$image[0])[red]&& $category==$image[2] [/red]){
        echo <<<HTML
<div class="floated">
    <a href="{$imageDir}{$big}{$image[0]}">
        <img src="{$imageDir}{$image[0]}">
    </a><br/>
    {$image[1]}
</div>

HTML;
    } //end the internal if
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top