简体   繁体   中英

Select next or previous image

  • Code Selects images from a directory and displays them in a table.does what I want, but, cant get the PREVIOUS or NEXT buttons to show next image. I have looked at many site and Stack but no luck, any help much appreciated

      <?php function RandomImage() { $randnum = 0; print("<UL>\\n"); $myDir = dir("./images"); $icount = 1; while($entryName = $myDir->read()) { $icount++; } $myDir->close(); $myDir = dir("./images"); rewinddir(); srand(time()); $randnum = rand(3,($icount-2)+1); for($i=0;$i<$randnum;$i++) { $entryName = $myDir->read(); $myimage = $entryName; } return('images/' . $myimage); } ?> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <title>Club Photo's</title> </head> <body> <?php $picture = RandomImage(); echo $picture; ?> <table width="250" height="237" border="2" cellpadding="0" cellspacing="3"> <tr> <br><td><div align="center">Club Photo's </div></td><br> </tr> <tr> <td><img name="myImage" src="<?php echo $picture; ?>" width="460" height="315" alt=""></td> </tr> </table> <br><input name="Previous" type="button" value="previous" /> <input name="Next" type="button" value="next" onClick=img name="myImage" src="<?php echo $picture; ?>"/> </body> 

Simple put two html button and if suppose you are showing six image at a time, then when user click on next button then simply hide first image and show seventh image and hide it through css and so on...same goes for previous button. Remember that when the last six images are shown, then the next button should not hide the first element inn the section..

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM