PHP Gallery problem... RESOLVED
Posted: Thu Jul 10, 2008 1:15 pm
Hi,
I am a relative newbie to PHP. I am currently building a photo gallery for an events website and I have most of the backend finished.
I am having a very basic problem with the homepage of the gallery.
Basically, the way I am designing is in a table with 2 columns;
- a column with a cover image for each album
- a column with thumbnails from that album
I want to display on the albums/image like this in rows. This is where I am having the problem...
I have the album cover image working fine but for some reason the same images are showing up for each album. I'm pretty sure it has something to do with a 'while' loop and the album id.
Below is the PHP code
I know this a basic problem, but help would be MUCH appreciated!!
Thanks,
Paul
PHP Code:
I am a relative newbie to PHP. I am currently building a photo gallery for an events website and I have most of the backend finished.
I am having a very basic problem with the homepage of the gallery.
Basically, the way I am designing is in a table with 2 columns;
- a column with a cover image for each album
- a column with thumbnails from that album
I want to display on the albums/image like this in rows. This is where I am having the problem...
I have the album cover image working fine but for some reason the same images are showing up for each album. I'm pretty sure it has something to do with a 'while' loop and the album id.
Below is the PHP code
I know this a basic problem, but help would be MUCH appreciated!!
Thanks,
Paul
PHP Code:
Code: Select all
<table border="0" cellpadding="5" cellspacing="0">
<?
$db_cnx = mysql_connect ('localhost', 'onoff', 'hello');
$db_select = mysql_query ('USE gallery');
$sql = "SELECT al_id, al_name, al_image, COUNT(im_album_id) AS al_numimage
FROM tbl_album al LEFT JOIN tbl_image im ON al.al_id = im.im_album_id
GROUP by al_id
ORDER BY al_name";
$result = mysql_query($sql) or die('Error, list album failed. ' . mysql_error());
while ($get_id = mysql_fetch_assoc($result)) { $albumid = $get_id['al_id'];}
$result = mysql_query($sql) or die('Error, list album failed. ' . mysql_error());
while ($row = mysql_fetch_assoc($result)) {
echo /*ECHO THE ALBUMS*/
'<tr>'.
'<td>'.
'<a href="index.php?page=list-image&album=' . $row['al_id'] . '">' .
'<img src="viewImage.php?type=album&name=' . $row['al_image'] . '" border="0">' .
'<br>' . $row['al_name'] . '</a><br />' . $numImages .
'</td>';
/*START GETTING THE IMAGES*/
$query2 = "SELECT im_id, im_title, im_thumbnail
FROM tbl_image
WHERE im_album_id = '$albumid'
ORDER BY im_title";
$result2 = mysql_query($query2) or die('Error, list image failed. ' . mysql_error());
while ($row2 = mysql_fetch_assoc($result2)) {
echo
/*ECHO THE IMAGES*/
'<td>'.
'<a href="?page=image-detail&album=' . $albumId . '&image=' . $row2['im_id'] . '">' .
'<img src="viewImage.php?type=glthumbnail&name=' . $row2['im_thumbnail'] . '" border="0">' .
'</td>';
}
echo '</tr>';
}
?>
</table>