jasonneo Posted November 20, 2007 Share Posted November 20, 2007 Hi all, Just started to learn php and an exercise is to do the following: Create an image gallery with a next and previous link. I have make use of an array and query string. So far i have just created an array and stored the image url's in the array like so... <?php $images = array(); $images[0] = '<img src="http://www.royalmail.com/images/royalmail/paarch/pa_rmlogo.gif"><br />'; $images[1] = '<img src="http://www.google.co.uk/intl/en_uk/images/logo.gif"><br />'; $images[2] = '<img src="http://www.gigablast.com/logo.gif"><br />'; for ($i = 0; $i < 3; $i ++) echo "$images[$i]" ; ?> <a href="">Next</a> So what i have so far just displayed the array contents basically. Can anyone help me as to how to actually cycle through the array wen next is clicked? Link to comment https://forums.phpfreaks.com/topic/78071-simple-php-gallery-help/ Share on other sites More sharing options...
trq Posted November 20, 2007 Share Posted November 20, 2007 <?php $images = array(); $images[0] = '<img src="http://www.royalmail.com/images/royalmail/paarch/pa_rmlogo.gif"><br />'; $images[1] = '<img src="http://www.google.co.uk/intl/en_uk/images/logo.gif"><br />'; $images[2] = '<img src="http://www.gigablast.com/logo.gif"><br />'; if (issset($_GET['id'])) { if ($_GET['id'] == count($images)-1) { $next = 0; } else { $next = $_GET['id']++; } echo $images[$_GET['id']]; } else { $next = 1; echo $images[0]; } ?> <a href="?id=<?php echo $next; ?>">Next</a> Link to comment https://forums.phpfreaks.com/topic/78071-simple-php-gallery-help/#findComment-395129 Share on other sites More sharing options...
jasonneo Posted November 20, 2007 Author Share Posted November 20, 2007 Thank you for the fast response, much appreciated. I understand most of that i think but when clicking next, it displays the same image/element which is $images[2] = '<img src="http://www.gigablast.com/logo.gif"><br />'; Link to comment https://forums.phpfreaks.com/topic/78071-simple-php-gallery-help/#findComment-395149 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.