AdRock Posted August 29, 2006 Share Posted August 29, 2006 I got this snippet of code from Barand and changed it for my purposes which works great.I am using it as the layout of an image gallery but would like a way of enlarging the image when a user either hovers over the image or clicks on it.I don't know what would be easier to have, a pop-up window with the enlarged image or to create a new page within my site with the enlarged image. If i had a new page how would i create the next/previous links for the imagesI don't want all these php image galleries with all the bells and whistles because they don't really suit my needs. I just need something simple[code]<?phpdefine ("NUMCOLS",4);include_once("includes/connection.php");$res = mysql_query("SELECT image FROM images");$count = 0;echo "<TABLE border=1>";while (list($image) = mysql_fetch_row($res)) { if ($count % NUMCOLS == 0) echo "<TR>\n"; # new row echo "<TD><img src='images/$image'></TD>\n"; $count++; if ($count % NUMCOLS == 0) echo "</TR>\n"; # end row}# end row if not already endedif ($count % NUMCOLS != 0) { while ($count++ % NUMCOLS) echo "<td> </td>"; echo "</TR>\n";}echo "</TABLE>";?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/19064-image-gallery-resolved/ Share on other sites More sharing options...
ronverdonk Posted August 29, 2006 Share Posted August 29, 2006 In my opinion the easiest way would be to have a separate thumnal page, to click on the thumbnail and to open a new window exactly the size of your original image and display it. That way you don't have to recalculate the available space for displaying the enlarged image on the same screen as the thumbnails. You could close window with the large image by just clicking on the image itself.BUT you'd need JavaScript to do all that.Last days I investigated the gallery class of Alf-red on [url=http://www.phpclasses.org/browse/package/3323.html]http://www.phpclasses.org/browse/package/3323.html[/url]You don't have to use it, just look at the technique used.Hope this helps a bit.Ronald 8) Quote Link to comment https://forums.phpfreaks.com/topic/19064-image-gallery-resolved/#findComment-82489 Share on other sites More sharing options...
AdRock Posted August 30, 2006 Author Share Posted August 30, 2006 This is my updated code which displays all the images but i would like to create a hyperlink from eacg of the images using thier id[code]<?phpdefine ("NUMCOLS",5);include_once("includes/connection.php");$res = mysql_query("SELECT * FROM images");$count = 0;echo "<TABLE border=0 id='gallery'>";while (list($thumb) = mysql_fetch_row($res)) { if ($count % NUMCOLS == 0) echo "<TR>\n"; # new row echo "<TD><a href='index.php?page=gallery&id=<? echo $res['id']; ?>'><img src='gallery/$thumb'></a></TD>\n"; $count++; if ($count % NUMCOLS == 0) echo "</TR>\n"; # end row}# end row if not already endedif ($count % NUMCOLS != 0) { while ($count++ % NUMCOLS) echo "<td> </td>"; echo "</TR>\n";}echo "</TABLE>";?>[/code]I have tried this but i get the usual error about unexpected T_ENCAPSED AND WHITESPACE. I can't see anywhere where whitespace would exist in the line with the hyperlink becuase it works perfectly if i take out the hyperlink. Quote Link to comment https://forums.phpfreaks.com/topic/19064-image-gallery-resolved/#findComment-83094 Share on other sites More sharing options...
ronverdonk Posted August 30, 2006 Share Posted August 30, 2006 You are using double single quotes in your echo. Do it like this[code]echo "<TD><a href='index.php?page=gallery&id=<? echo $res[id]; ?>'><img src='gallery/$thumb'></a></TD>\n";[/code]Ronald 8) Quote Link to comment https://forums.phpfreaks.com/topic/19064-image-gallery-resolved/#findComment-83097 Share on other sites More sharing options...
AdRock Posted August 30, 2006 Author Share Posted August 30, 2006 I have got the first page to work how i want[code]<?phpdefine ("NUMCOLS",5);include_once("includes/connection.php");$res = mysql_query("SELECT id, thumb FROM images");$count = 0;echo "<TABLE border=0 id='gallery'>";while (list($id,$thumb) = mysql_fetch_row($res)) { if ($count % NUMCOLS == 0) echo "<TR>\n"; # new row echo "<TD><a href='/image/$id'><img src='/gallery/$thumb' style='border:none'></a></TD>\n"; //echo "<TD><img src='gallery/$thumb'></TD>\n"; $count++; if ($count % NUMCOLS == 0) echo "</TR>\n"; # end row}# end row if not already endedif ($count % NUMCOLS != 0) { while ($count++ % NUMCOLS) echo "<td> </td>"; echo "</TR>\n";}echo "</TABLE>";?>[/code]But when the new page opens which is supposed to display the enlarged image, it displays nothing. Here is the code but i can't put my finger on it why it won't work....![code]<?phpinclude_once("includes/connection.php");$id=$_GET['id'];$res = mysql_query("SELECT * FROM images where id='$id'");while ($row = mysql_fetch_row($res)) { echo "<img src='/gallery/".$row['image']."'>";}?>[/code]I did get it to display all the images in one column a minute ago before i put the where clause in the SQL statement Quote Link to comment https://forums.phpfreaks.com/topic/19064-image-gallery-resolved/#findComment-83146 Share on other sites More sharing options...
ronverdonk Posted August 30, 2006 Share Posted August 30, 2006 I can't see that you pass the id (as in $_GET['id']) in your url.[code]echo "<TD><a href='/image/$id'><img src='/gallery/$thumb' style='border:none'></a></TD>\n";[/code]Ronald 8) Quote Link to comment https://forums.phpfreaks.com/topic/19064-image-gallery-resolved/#findComment-83153 Share on other sites More sharing options...
AndyB Posted August 30, 2006 Share Posted August 30, 2006 If that last post doesn't solve the problem, then view the html source code of the generated single image page. That'll tell you something about why the image doesn't show. Quote Link to comment https://forums.phpfreaks.com/topic/19064-image-gallery-resolved/#findComment-83155 Share on other sites More sharing options...
AdRock Posted August 30, 2006 Author Share Posted August 30, 2006 In that line you highlighted $id is the id of the image in the url (i'm using mod rewrite) so as i click on different images the different ids are shown in the address bar Quote Link to comment https://forums.phpfreaks.com/topic/19064-image-gallery-resolved/#findComment-83170 Share on other sites More sharing options...
AdRock Posted August 30, 2006 Author Share Posted August 30, 2006 I know what is causing the problemif i use this[code]echo "<TD><a href='index.php?page=image&id=$id'><img src='/gallery/$thumb' style='border:none'></a></TD>\n";[/code]it works but when i try to mod rewrite the url to this[code]echo "<TD><a href='/image/$id'><img src='/gallery/$thumb' style='border:none'></a></TD>\n";[/code]that stops the image being displayed Quote Link to comment https://forums.phpfreaks.com/topic/19064-image-gallery-resolved/#findComment-83177 Share on other sites More sharing options...
AdRock Posted August 31, 2006 Author Share Posted August 31, 2006 Is there another way of displaying the chosen image in a page called image.phpI can't use $_GET[id'] becuase the rewritten url (mod rewrite) doesn't show id in the address bar Quote Link to comment https://forums.phpfreaks.com/topic/19064-image-gallery-resolved/#findComment-83455 Share on other sites More sharing options...
wildteen88 Posted August 31, 2006 Share Posted August 31, 2006 Looks like you have an error with your mod_rewrite rules then. mod_rewrite shouldnt stop your GET paramters from working, as it passes them with the rewrite rule.read my reply [url=http://www.phpfreaks.com/forums/index.php/topic,106374.msg425418.html#msg425418]here[/url]. I have closed that topic in the Apache forum too. Dont double post topics Quote Link to comment https://forums.phpfreaks.com/topic/19064-image-gallery-resolved/#findComment-83566 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.