marcbraulio
Baseband Member
- Messages
- 51
So I am building a Image Scroller in which the images are grabbed from a specific directory and display in a Jquery animated div, so managed to do that successfully using the following code:
Now I am trying to do the same to fill in a different link for each image based on what the user put on the text file. So I did the following:
It worked except the images begin to repeat themselves, can anyone show me the right way to have two foreach statements grabbing information from two different sources but displaying all on one output?
PHP:
//path to directory to scan
$directory = "photos/";
//get all image files with a .jpg extension.
$images = glob("" . $directory . "{*.jpg,*.gif,*.png}", GLOB_BRACE);
//print each file name
foreach($images as $image)
{
echo "<a href=\"www.google.com\" title=\"image\"><img src=\"$image\" alt=\"Demo image\"></a>";
}
Now I am trying to do the same to fill in a different link for each image based on what the user put on the text file. So I did the following:
PHP:
//path to directory to scan
$directory = "photos/";
//get all image files with a .jpg extension.
$images = glob("" . $directory . "{*.jpg,*.gif,*.png}", GLOB_BRACE);
$fp = file('links.txt');
//print each file name
foreach($images as $image)
{
foreach($fp as $link) {
echo "<a href=\"$link\" title=\"image\"><img src=\"$image\" alt=\"Demo image\"></a>";
}
}
It worked except the images begin to repeat themselves, can anyone show me the right way to have two foreach statements grabbing information from two different sources but displaying all on one output?