Jump to content

creating a rather complex gallery


slaterino

Recommended Posts

Hi,

I have created a standard-ish cms image gallery with two categories of pictures; albums and gallery images. Currently, all the album thumbnails show on the main page. When you click on the image all of the gallery thumbnails are displayed. You then click on the thumbnail for the full picture. Quite simple stuff, however I am looking to add a variable to the gallery images. This will be a yes or no column in the table, and is where it gets a bit complex. When the answer is yes I want the name of the image to be displayed underneath the album that it belongs to. I have included the code for the view album page below. There are a few things that are a bit over my head in terms of doing this:

1. i will now be selecting data from two tables. Do I just add the extra fields from the new table, and the table to the SELECT query at the top

2. would I use an 'if' statement to check whether the new column is yes or no, i.e. if ($trophy=yes)

3. the current code is based on a tutorial and i don't fully understand the structure. if anyone could point me as to where i can add new code for these extra rows in the code that would be great. basically the new rows which are for the 'yes' fields will just be a new '<tr>' under the last one.

 

I hope this makes sense.

 

<?php
$sql  = "SELECT al_id, al_order, al_name, al_description, 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_order";
$result = mysql_query($sql) or die('Error, list album failed. ' . mysql_error());

if (mysql_num_rows($result) == 0) {
echo "No album yet";
} else {

echo '<table width="480" border="0" cellspacing="1" cellpadding="2" align="left">';

// the album is listed in a table 
// here we specify how many columns 
// we want to show on each row 
$colsPerRow = 3;

// width of each column in percent
$colWidth   = (int)(100/$colsPerRow);
$i = 0;
while ($row = mysql_fetch_assoc($result)) {
	if ($i % $colsPerRow == 0) {
		// start a new row
		echo '<tr>';
	}

	$numImages = $row['al_numimage'] > 1 ? $row['al_numimage'] . ' images' : $row['al_numimage'] . ' image';

	echo '<td width="150px">' . 
	     '<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></td>';

	if ($i % $colsPerRow == $colsPerRow - 1) {
		// end this row
		echo '</tr>';
	}		

	$i += 1;
}

// print blank columns
if ($i % $colsPerRow != 0) {
	while ($i++ % $colsPerRow != 0) {
		echo '<td width="' . $colWidth . '%"> </td>';
	}	
	echo '</tr>';
}	

echo '</table>';


}
?>

Link to comment
https://forums.phpfreaks.com/topic/120585-creating-a-rather-complex-gallery/
Share on other sites

Archived

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

×
×
  • 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.