Jump to content

image gallery [RESOLVED]


AdRock

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]
Link to comment
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)
Link to comment
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.
Link to comment
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
Link to comment
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
Link to comment
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
Link to comment
Share on other sites

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.