Jump to content

Recommended Posts

Learning php and need advice on how to create a simple image display of only the image(similar to http://www.sweetconcrete.com/CounterTopSamples/pages/p74_jpg.htm style), starting at P71 and being able to go through all the pics from 71-76 through next and previous links, but not sure how to go about it... Also looking at making it so if it is beginning image, there will be no previous link, and vice-versa for last. Looked for so many solutions, but all more complex than what I want and can't help.

Here's what I've got...

defs.php 

<?php

  $jpgdir = "pics/jpgpics/";

  $descdir ="descriptions/txt/"; 

  $self = $_SERVER['PHP_SELF'];

 

?>

 

file 2

 

<?php

require("defs.php");

 

$id = 71;

 

$last = 76;

$first = 71;

 

 

$file = "../../pics/jpgpics/P71.JPG";

$caption = "No description";

 

echo "<html><head>";

echo "<title>My Gallery</title>";

echo "</head><body>";

echo "<h1>Gallery 09</h1>";

echo "<p><img src=\"$file\"></p>";

 

 

echo "<a href=\"\">PREVIOUS </a>";

echo "<a href=\"$self?id=$id\">NEXT</a>";

echo "</body></html>";

?>

 

Any help/advice always appreciated :)

 

Link to comment
https://forums.phpfreaks.com/topic/172845-help-with-using-php-over-many-pages/
Share on other sites

you could use a get variable and use that to decide which image to show. For example

 

$id = (isset($_GET['id'])) ? $_GET['id'] : 71;//will assign id with either the get variable if its set, or the default value, 71

//make sure $id is valid
if ($id < $first || $id > $last){
//not a valid id
echo "Sorry but the image could not be found!";
exit();
}

$last = 76;
$first = 71;


$file = "../../pics/jpgpics/P".$id.".jpg";
$caption = "No description";

//show the image
echo "<html><head>";
echo "<title>My Gallery</title>";
echo "</head><body>";
echo "<h1>Gallery 09</h1>";
echo "<p><img src=\"$file\"></p>";

//now for the links
if ($id != $first){//only show prev link if we aren't at the first image
echo "<a href=\"$self?id=".($id-1)."\">PREVIOUS </a>";
}
if ($id != $last){//only show next link if we arent at last image
echo "<a href=\"$self?id=".($id+1)."\">NEXT</a>";
}
echo "</body></html>";
?>

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.