Suchy Posted May 1, 2007 Share Posted May 1, 2007 I have a simple page that takes url to images from MySQL and displays them, its basicaly something like: <?php foreach($photos as $x) { ?> <img src="<?php print($x['url']); ?>"> </img> <?php } ?> Now I want to add a link next to each photo so that when someone clicks on it it will take them to a new page with just thet one photo. How can I do this? Quote Link to comment https://forums.phpfreaks.com/topic/49453-solved-image-gallery/ Share on other sites More sharing options...
redarrow Posted May 1, 2007 Share Posted May 1, 2007 Have you got in the database a timestamp or somthink to relate to that pic example a id. Quote Link to comment https://forums.phpfreaks.com/topic/49453-solved-image-gallery/#findComment-242378 Share on other sites More sharing options...
Suchy Posted May 1, 2007 Author Share Posted May 1, 2007 Yeah that table just has 2 fields ,an unique auto generated id and the url Quote Link to comment https://forums.phpfreaks.com/topic/49453-solved-image-gallery/#findComment-242380 Share on other sites More sharing options...
DaveEverFade Posted May 1, 2007 Share Posted May 1, 2007 This should do it... <?php foreach($photos as $x) { ?> <img src="<?php print($x['url']); ?>"> </img><a href="<?php print($x['url']); ?>">Link text</a> <?php } ?> Quote Link to comment https://forums.phpfreaks.com/topic/49453-solved-image-gallery/#findComment-242381 Share on other sites More sharing options...
MadTechie Posted May 1, 2007 Share Posted May 1, 2007 update for DaveEverFades code <?php foreach($photos as $x) { ?> <img src="<?php print($x['url']); ?>"> </img><a href="<?php print($x['url']); ?>" target='_blank' >Link text</a> <?php } ?> revised <?php foreach($photos as $x) { echo "<img src='{$x['url']}'></img><a href='{$x['url']}' target='_blank' >Link text</a>"; } ?> EDIT: missed the _ Quote Link to comment https://forums.phpfreaks.com/topic/49453-solved-image-gallery/#findComment-242384 Share on other sites More sharing options...
redarrow Posted May 1, 2007 Share Posted May 1, 2007 here an easer way sorry but might have errors but your get the idear ok. pictures.php <?php foreach($photos as $x) { ?> <?php echo"<a href='new_pic.php?cmd=".$x['url']." '>?> <img src="<?php print($x['url']); ?>"> </img></a>"; <?php } ?> new_pic.php <?php echo"<img src='".$_GET['cmd']."'> </img>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/49453-solved-image-gallery/#findComment-242386 Share on other sites More sharing options...
Suchy Posted May 1, 2007 Author Share Posted May 1, 2007 I had that before, the problem is that the link takes you just to the picture, I want it to take you to a new page whrer the picture will be, with some other stuff. Quote Link to comment https://forums.phpfreaks.com/topic/49453-solved-image-gallery/#findComment-242390 Share on other sites More sharing options...
MadTechie Posted May 1, 2007 Share Posted May 1, 2007 ok <?php foreach($photos as $x) { echo "<img src='{$x['url']}'></img><a href='page2.php?image={$x['url']}' target='_blank' >Link text</a>"; } ?> page2.php <?php echo "hello<br>"; echo "<img src='{$_GET['image']}'></img>"; echo "world<br>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/49453-solved-image-gallery/#findComment-242398 Share on other sites More sharing options...
Suchy Posted May 1, 2007 Author Share Posted May 1, 2007 That's it, thank you. Quote Link to comment https://forums.phpfreaks.com/topic/49453-solved-image-gallery/#findComment-242418 Share on other sites More sharing options...
redarrow Posted May 1, 2007 Share Posted May 1, 2007 Sorry i done it to quick but here my version ok. pic.php <?php //build an array off pictures and the folder exstention. $pic=array("images/1.png","images/2.png","images/3.png"); // get the pictures from the array. foreach($pic as $x){ // echo a link to a new page to show the picture the user press on. echo"<center><a href='new_pic.php?cmd=".$x."'><img src='$x'></img></a><br><br></center>"; } ?> place the img src tag anywere it needs to be displayed. new_pic.php <?php // show picture from the url using the $_GET statement. echo "<img src='".$_GET['cmd']."'>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/49453-solved-image-gallery/#findComment-242425 Share on other sites More sharing options...
MadTechie Posted May 1, 2007 Share Posted May 1, 2007 Can you click solved please Quote Link to comment https://forums.phpfreaks.com/topic/49453-solved-image-gallery/#findComment-242429 Share on other sites More sharing options...
Suchy Posted May 1, 2007 Author Share Posted May 1, 2007 Also this is kind off-topic, but I found a script that places a watermark on top of the picture: <?php // 'watermark' in the upper left of an image $my_text = 'watermark'; // open image and lay white text on it.. $img = imagecreatefromgif ('testpic.gif'); $white = imagecolorallocate($img, 255, 255, 255); // white imagestring($img, 4, 6, 3, $my_text, $white); // size 4 built-in font // send the image //header("Content-type: image/jpeg"); imagegif($img); imagedestroy($img); ?> So what link should be used in the: $img = imagecreatefromgif (????); also how can I distinguish if it is a jpg, gif, png... ? Quote Link to comment https://forums.phpfreaks.com/topic/49453-solved-image-gallery/#findComment-242436 Share on other sites More sharing options...
MadTechie Posted May 1, 2007 Share Posted May 1, 2007 well firstly you it would be better if you have a folder with you images in and hold the image filename, as for the script try this image.php?image=doggy.jpg <?php // 'watermark' in the upper left of an image $my_text = 'watermark'; // open image and lay white text on it.. $img = imagecreatefromgif ('testpic.gif'); $white = imagecolorallocate($img, 255, 255, 255); // white imagestring($img, 4, 6, 3, $my_text, $white); // size 4 built-in font // send the image header("Content-type: image/gif"); imagegif($img); imagedestroy($img); ?> change page2.php to image.php in my previous script, to get the filetype you can just get the last 3 characters (won't work on renamed files ie test.gif to test.jpg) for jpeg use imagecreatefromjpeg and imagejpeg a switch to break them into groups would be best Quote Link to comment https://forums.phpfreaks.com/topic/49453-solved-image-gallery/#findComment-242537 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.