Jump to content


Photo

image gallery [RESOLVED]


  • Please log in to reply
10 replies to this topic

#1 AdRock

AdRock
  • Members
  • PipPipPip
  • Advanced Member
  • 911 posts

Posted 29 August 2006 - 09:41 PM

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

<?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>";
?>

If your topic has been solved, please mark the topic as SOLVED.

This helps others from identifying which topics need help still

#2 ronverdonk

ronverdonk
  • Members
  • PipPipPip
  • Advanced Member
  • 277 posts
  • LocationNetherlands

Posted 29 August 2006 - 10:25 PM

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 http://www.phpclasse...ckage/3323.html

You don't have to use it, just look at the technique used.
Hope this helps a bit.

Ronald  8)
RTFM is an almost extinct art form, it should be subsidized.

#3 AdRock

AdRock
  • Members
  • PipPipPip
  • Advanced Member
  • 911 posts

Posted 30 August 2006 - 07:52 PM

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

<?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>";
?>

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.
If your topic has been solved, please mark the topic as SOLVED.

This helps others from identifying which topics need help still

#4 ronverdonk

ronverdonk
  • Members
  • PipPipPip
  • Advanced Member
  • 277 posts
  • LocationNetherlands

Posted 30 August 2006 - 07:59 PM

You are using double single quotes in your echo. Do it like this
echo "<TD><a href='index.php?page=gallery&id=<? echo $res[id]; ?>'><img src='gallery/$thumb'></a></TD>\n";

Ronald  8)
RTFM is an almost extinct art form, it should be subsidized.

#5 AdRock

AdRock
  • Members
  • PipPipPip
  • Advanced Member
  • 911 posts

Posted 30 August 2006 - 09:40 PM

I have got the first page to work how i want
<?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>";
?>

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....!
<?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']."'>";
}

?>
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
If your topic has been solved, please mark the topic as SOLVED.

This helps others from identifying which topics need help still

#6 ronverdonk

ronverdonk
  • Members
  • PipPipPip
  • Advanced Member
  • 277 posts
  • LocationNetherlands

Posted 30 August 2006 - 09:55 PM

I can't see that you pass the id (as in $_GET['id']) in your url.

echo "<TD><a href='/image/$id'><img src='/gallery/$thumb' style='border:none'></a></TD>\n";

Ronald  8)

RTFM is an almost extinct art form, it should be subsidized.

#7 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 30 August 2006 - 09:57 PM

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.
Legend has it that reading the manual never killed anyone.
My site

#8 AdRock

AdRock
  • Members
  • PipPipPip
  • Advanced Member
  • 911 posts

Posted 30 August 2006 - 10:21 PM

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
If your topic has been solved, please mark the topic as SOLVED.

This helps others from identifying which topics need help still

#9 AdRock

AdRock
  • Members
  • PipPipPip
  • Advanced Member
  • 911 posts

Posted 30 August 2006 - 10:50 PM

I know what is causing the problem

if i use this
echo "<TD><a href='index.php?page=image&id=$id'><img src='/gallery/$thumb' style='border:none'></a></TD>\n";
it works but when i try to mod rewrite the url to this
echo "<TD><a href='/image/$id'><img src='/gallery/$thumb' style='border:none'></a></TD>\n";
that stops the image being displayed
If your topic has been solved, please mark the topic as SOLVED.

This helps others from identifying which topics need help still

#10 AdRock

AdRock
  • Members
  • PipPipPip
  • Advanced Member
  • 911 posts

Posted 31 August 2006 - 01:26 PM

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
If your topic has been solved, please mark the topic as SOLVED.

This helps others from identifying which topics need help still

#11 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 31 August 2006 - 04:21 PM

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 here. I have closed that topic in the Apache forum too. Dont double post topics





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users