Jump to content

Simple php gallery, help!


jasonneo

Recommended Posts

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

<?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>

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.