Jump to content

Archived

This topic is now archived and is closed to further replies.

AdRock

image gallery [RESOLVED]

Recommended Posts

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 images

I 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]<?php
define ("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 ended

if ($count % NUMCOLS != 0) {
   while ($count++ % NUMCOLS) echo "<td>&nbsp;</td>";
   echo "</TR>\n";
}
echo "</TABLE>";
?>[/code]

Share this post


Link to post
Share on other sites
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)

Share this post


Link to post
Share on other sites
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]<?php
define ("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 ended

if ($count % NUMCOLS != 0) {
  while ($count++ % NUMCOLS) echo "<td>&nbsp;</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.

Share this post


Link to post
Share on other sites
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)

Share this post


Link to post
Share on other sites
I have got the first page to work how i want
[code]<?php
define ("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 ended

if ($count % NUMCOLS != 0) {
  while ($count++ % NUMCOLS) echo "<td>&nbsp;</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]<?php

include_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

Share this post


Link to post
Share on other sites
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)

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
I know what is causing the problem

if 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

Share this post


Link to post
Share on other sites
Is there another way of displaying the chosen image in a page called image.php

I can't use $_GET[id'] becuase the rewritten url (mod rewrite) doesn't show id in the address bar

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

×

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.