tyrant79 Posted September 2, 2009 Share Posted September 2, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/172845-help-with-using-php-over-many-pages/ Share on other sites More sharing options...
trq Posted September 2, 2009 Share Posted September 2, 2009 Its called pagination. Should be plenty of tutorials on the subject. Are your image paths stored within a db? Quote Link to comment https://forums.phpfreaks.com/topic/172845-help-with-using-php-over-many-pages/#findComment-910967 Share on other sites More sharing options...
mikesta707 Posted September 2, 2009 Share Posted September 2, 2009 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>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/172845-help-with-using-php-over-many-pages/#findComment-910971 Share on other sites More sharing options...
tyrant79 Posted September 2, 2009 Author Share Posted September 2, 2009 Wow, thank you both; points me in... well... a much better direction than before to give it another shot Quote Link to comment https://forums.phpfreaks.com/topic/172845-help-with-using-php-over-many-pages/#findComment-910982 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.