photo gallery

Ask about a PHP problem here.
User avatar
Robbedoesie
Posts: 97
Joined: Thu May 19, 2011 7:37 pm
Location: Enkhuizen, Holland

Re: photo gallery

Post by Robbedoesie »

I am still trying to get the main image on the same page as the thumbnails and still I am not succeeding. I am still trying because I think it must be possible.

I have a few questions.
Where you use $image on line 38 above it will not have an array value since you define it as false near the top. I'm not really sure what should be in it's place :/ maybe it should be based on $_GET['image_id'] ? You could keep the value form the loop too, you would just need to use a different variable name.

After the $image = false; I can't use the variable $image anymore, it then maybe should be based on $_GET['image_id']. Can you give my an example of how I could do that because I don't know what you mean. Or I could keep the value of the loop but then with a different variable name. I tried for example $image = $img to get a different variable name with the value from the loop but maybe it is not a good way to change a variable name?

The code is now;
[syntax=php]<?php
include 'core/init.php';

if (isset($_GET['album_id'])) {
$album_id = $_GET['album_id'];
$album_data = album_data($album_id, 'name', 'description');

echo '<h3>', $album_data['name'], '</h3><p>', $album_data['description'], '</p>';

$albums = get_albums();
$images = get_images($album_id);
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<div id="wrap">
<div id="sidebarleft">
<?php

if (empty($images)) {
echo 'Er zijn geen foto\'s in dit album';
} else {
foreach ($albums as $album) {
$image = true;
foreach ($images as $image) {
echo'<a href="view_album.php?album_id=', $album['alb_id'],'&image_id=uploads/', $image['album'], '/', $image['id'], '.', $image['ext'], '"><img src="uploads/thumbs/', $image['album'], '/', $image['id'], '.', $image['ext'], '" title="" /></a><a href="delete_image.php?image_id=', $image['id'],'">x</a> ';
$image = false;
}
if(!$image) break;
}
}
?>
</div>
<div id="imagecontainer">
<div id="image">
<?php
$image = (int)$image;
$full_image=(isset($_GET['image_id'])) ? $_GET['image_id'] : (int)$images[0];
var_dump($images);
echo'<a href="?image_id=uploads/', $image['album'], '/', $image['id'], '.', $image['ext'], '"><img src="',htmlentities($full_image), '" title="" />';
?>
[/syntax]
After $image = false; I try to change the $image variable in an integer. I hoped that I could use the $image variable again but it is not working.

I hope you can help me out here, thanks.
http://www.robcnossen.nl/view_album.php?album_id=7
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: photo gallery

Post by jacek »

Sorry for the delay, it looks like you worked it out though :D ?
Image
User avatar
Robbedoesie
Posts: 97
Joined: Thu May 19, 2011 7:37 pm
Location: Enkhuizen, Holland

Re: photo gallery

Post by Robbedoesie »

He Jacek,
Sorry for the delay, it looks like you worked it out though :D ?

no problem, I hope you are alright.

I recently find out that the problem was not with the images but with the albums. I find that out when I added another album, so I had then four albums instead of three albums and suddenly I had four thumbnails of each image instead of three thumbnails of each image.
At first I didn't made a link between the amount of albums and the same amount of thumbnails, but after adding the fourth album I did.
Still it took a while before I could solve this problem but finally I did :D .
this one line solved the thumbnail problem;[syntax=php]if ($image['album'] === $album['id'])[/syntax].

Now this is settled I hope it is easier to find the image source for showing an image immediately after opening the image gallery page. If I think am not able to solve this problem I come back to your forum.
User avatar
Robbedoesie
Posts: 97
Joined: Thu May 19, 2011 7:37 pm
Location: Enkhuizen, Holland

Re: photo gallery

Post by Robbedoesie »

well, I am not get the problem solved as how I want it to.
I can get now show an image immediately after opening the image gallery page, but the problem now is that it won't go away when I click on a thumbnail. So there are two images sort of fighting for one spot.
http://www.robcnossen.nl/view_album.php?album_id=7
This is the code what belongs to this;
[syntax=php]$full_image=(isset($_GET['image_id'])) ? $_GET['image_id'] : (isset($images['img_name']));
echo'<a href="?image_id=uploads/', $image['album'], '/', $image['id'], '.', $image['ext'], '">

<img src="uploads/' ,$image['album'], '/' ,$image['id'], '.' ,$image['ext'],htmlentities($full_image), '" title="" />';[/syntax]
I am trying to solve this problem with for example this;
[syntax=php]if(isset($_GET['image_id'])){
$full_image = $_GET['image_id'];

}elseif(isset($images['img_name'])){
$full_image = $images['img_name'];
//break;
}
$full_image = (isset($images['img_name'])) or (isset($_GET['image_id']));
echo'<a href="?image_id=uploads/', $image['album'], '/', $image['id'], '.', $image['ext'], '">
<img src="uploads/' ,$image['album'], '/' ,$image['id'], '.' ,$image['ext'],htmlentities($full_image), '" title="" >';[/syntax]
I thought that if I break after $images['img_name']; that this part was taking place for $_GET['image_id'];. But the $images['img_name']; part is now staying at his place, there is no place at all for another image, if I break or not it makes no difference.

Am I on the right track to solve this problem, what am I doing wrong here?
Thanks...
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: photo gallery

Post by jacek »

Robbedoesie wrote:Am I on the right track to solve this problem, what am I doing wrong here?

Basically no. $images is not defined at the point you are trying to use it.
Image
Post Reply