Forum Moderators: coopster

Message Too Old, No Replies

Text file array into varaibles then into a for loop

         

BandonRandon

6:33 pm on May 1, 2008 (gmt 0)

10+ Year Member



Hello,

I am a graphic designer who does some programming but a lot of it is out of my realm. This is one of those cases. I have all the code written except for the last "for loop". Here is what I'm trying to do: I'm trying to use a text file to call images into a loop for displaying as gallery. the first item is the image name and the second is the description seperated by a ";"

Here is the contents of the text file:


Image1.gif;Image1 Description
Image2.gif;Image2 Description
Image3.gif;Image3 Description
Image4.gif;Image4 Description

Here is the php code i'm trying to use:


$pic_info = file("$path_to_project/$pic_info_file");
$number_pics = count ($pic_info);


if (($currentPic > $number_pics)¦¦($currentPic == $number_pics)¦¦!$currentPic)
$currentPic = '0';
}


$item = preg_split('/;/', rtrim($pic_info[$currentPic]), 2);
$image_title = isset($item[1]) ? $item[1] : '';
$images .= "$item[0]";
$first_image = "$item[0]";


echo('<a href="'. $first_image . '" rel=lightbox[' . $path_to_project .'] class="highlight" title="$image_title"><img src="'. $project_thumb_url . '" width="200" /></a>');
echo("<div style=\"display:none\">");


//this code needs to loop:
echo('<a href="'. /* the remaining file names need to loop here */ . '" rel="lightbox[' . $path_to_project. ']" title="'. /*description after the l needs to go here */ .'"></a>');
//end loop


echo("</div>");

d40sithui

3:24 pm on May 2, 2008 (gmt 0)

10+ Year Member



interesting project.
I'm assuming $currentPic is the selected image and possibly enhanced in some way. also, it's an integer that matches with the array key in $pic_info. this is what im thinking. remember this will load only the remaining pictures - not the previous. you'd probably need another loop to do the previous, or put them all in one big loop.

for($i = $currentPic+1; $i < sizeof($pic_info); $i++){
$item = explode(";", $pic_info[$i]);
echo('<a href="'.$item[0]. '" rel="lightbox[' . $path_to_project. ']" title="'.$item[1].'"></a>');
}

BandonRandon

6:11 pm on May 5, 2008 (gmt 0)

10+ Year Member



Thank you, i'll play with this a bit and hopefully get it to work!