Jump to content

next link to cycle through array values


xtiancjs

Recommended Posts

Hi, Am on the right track I think , What I want to do is create a next link that will cycle through all the values of an array. In this case the values are images and I would like to load them into their own page or <div> on the click of NEXT . so far I have managed to create the array and load the first image correctly.

I have deleted any duplicate and empty array values as well.After an initial click the next link is only cycling through the lowest 2 values and not all values. Does this have something to do with the array resorting itself on each page load? Not too sure . Here is the code I have so far:

 

<?php require_once('../Connections/nancy.php'); ?>
<?php
$iid = $_GET['imageID'];
$image = $_GET['imagenameID'];
$artist = $_GET['artistID'];
$dir = "../artist_images/$artist/";
$dh = opendir($dir);
while (false !== ($file = readdir($dh))) {
$files[] = $file;
}
$nfiles = array_unique($files);
foreach($nfiles as $key => $value) {
  if($value == "..") {
unset($nfiles[$key]);
  } elseif($value == ".") {
    unset($nfiles[$key]);
  }elseif($value == "") {
    unset($nfiles[$key]);
  }
}
$new_array = array_values($nfiles);
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>

</head>

<body>
<div id="image"> <img src="<?php  echo "$dir/$image"; ?>" > </div>
<?php echo "$dir"; ?>
<?php  
          
	   print_r($nfiles);//to see values

	   $next_image = next($nfiles);  ?>
	   <a href="image_detail.php?artistID=<?php echo "$artist"; ?>&imagenameID=<?php  echo "$next_page"; ?>">next</a>

</body>
</html>

 

Thanks for any help!!

Link to comment
https://forums.phpfreaks.com/topic/44158-next-link-to-cycle-through-array-values/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

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