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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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