I’m trying to make an update-able gallery. The navigation bar consists of a simple form which uses php to build a drop-down list of directories (gallery names). When the user clicks on one, it shows the contents as a new gallery.
It sort of works. HOWEVER, only the original gallery works as a clickable thumbnail that generates the correct main image. I keep running into three different problems:
- The correct gallery shows, but the $now_viewing variable doesn’t seem to take. For example, if I’ve clicked gallery_B and it looks right, I click one of its thumbnails, and the error says “function getimagesize[] link/gallery_A/$main_image”. No such file or directory.
- Otherwise, if it reads the correct gallery, say gallery_c, then the error reads “function getimagesize[] link/gallery_c/image_from_gallery_A. No such file or directory”
- Last, when I click around on the original, refreshed page gallery (using the default dir), it works fine. HOWEVER, I’m unable to choose a new gallery after clicking around, because the $_GET information is in the address bar. But, if I refresh, then I lose the $_POST $variable, and return to default.
I think the answer is in turning this into several pages. But, not sure how just yet…If anyone can help, I’ll tell Santa to treat you right this year.
[php]<?php
if (! @include(‘connection’)) {
echo ‘Sorry, the database is unavailable’;
exit;
}
define(‘COLS’,3);
define(‘GALMAX’,9);
$conn = //connect;
if (array_key_exists(‘selectDir’,$_POST)) {
$now_viewing = $_POST[‘directory’];
$SESSION[‘now_viewing’] = $now_viewing;
// $gallery_title = str_replace(’’,’ ‘,$now_viewing);
$getTotal = “SELECT COUNT() FROM sale_items WHERE gallery_name = ‘$now_viewing’";
$total = mysql_query($getTotal);
$row = mysql_fetch_row($total);
$total_images = $row[0];
//set current page
$curPage = isset($_GET[‘curPage’])? $GET[‘curPage’]:0;
$startRow = $curPage * GALMAX;
$sql = “SELECT * FROM sale_items WHERE gallery_name = ‘$now_viewing’”.“LIMIT $startRow,”.GALMAX;
$result = mysql_query($sql) or die(mysql_error());
$row = mysql_fetch_assoc($result);
}
elseif (!$POST)) {
//or else scan the directory, and show the first item
$contents = scandir(‘main_directory’);
$found = array();
foreach ($contents as $item) {
$DirInfo = pathinfo($item);
if(array_key_exists(‘dirname’,$DirInfo) && !array_key_exists(‘extension’,$DirInfo)) {
$found[] = $item;
}
}
if ($found) {
natcasesort($found);
foreach($found as $dirname) {
$now_viewing = str_replace(’’,’ ‘,$found[1]);
}
}
// $gallery_title = str_replace(’’,’ ',$now_viewing);
$getTotal = "SELECT COUNT() FROM sale_items WHERE gallery_name = ‘$now_viewing’”;
$total = mysql_query($getTotal);
$row = mysql_fetch_row($total);
$total_images = $row[0];
//set current page
$curPage = isset($_GET[‘curPage’])? $_GET[‘curPage’]:0;
$startRow = $curPage * GALMAX;
$sql = “SELECT * FROM sale_items WHERE gallery_name = ‘$now_viewing’”.“LIMIT $startRow,”.GALMAX;
$result = mysql_query($sql) or die(mysql_error());
$row = mysql_fetch_assoc($result);
}
//find a default main image to display
if (isset($_GET[‘image’])) {
$mainImage = $_GET[‘image’];
}
else {
$mainImage = $row[‘filename’];
}
$imageSize = getimagesize(’…/directory_handle/’.$now_viewing."/$mainImage");
?>
See Other Sale <?php //other items are built from here include('../../includes/BuildDirListFunction'); buildDirList ('/path/'); ?>
<input name="selectDir" id="selectDir" type="submit" value="Go" />
</p>
</form>
</div>
<div id="Crumbs_Right">
<p>Displaying <?php echo $startRow+1;
if ($startRow+1 < $total_images) {
echo ' to ';
if ($startRow+GALMAX < $total_images) {
echo $startRow+GALMAX;
}
else {
echo $total_images;
}
}
echo " of $total_images";
?>
</div>
<div id="Crumbs_Right">
<?php
if($curPage > 0) {
echo '<a href="'.$_SERVER['PHP_SELF'].'?curPage='.($curPage-1).'"><< Prev</a>';
}
else {
echo ' ';
}
?>
<?php
//forward link
if($startRow+GALMAX < $total_images) {
echo '<a href="'.$_SERVER['PHP_SELF'].'?curPage='.($curPage+1).'"> Next >></a>';
}
else {
echo ' ';
}
?>
</p>
</div>
</div><!----------------END <GalleryNav-->
<div id="Thumbs">
<table>
<tr>
<?php
//count
$pos = 0;
do {
?>
<td><a href="<?php echo $_SERVER['PHP_SELF']; ?>?image=<?php echo $row['filename']; ?>&curPage=<?php echo $curPage; ?>"><img src="gallery_path/<?php echo $now_viewing."/thumbs/".$row['filename']; ?>" alt ="<?php echo $row['filename']; ?>" /></td>
<?php
$row = mysql_fetch_assoc($result);
$pos++;
//if at end of row, insert tags as needed
if ($pos%COLS === 0 && is_array($row)) {
echo '</tr><tr>';
}
} while ($row);
//new loop for final row
while ($pos%COLS) {
echo '<td> </td>';
$pos++;
}
?>
</tr>
</table>
</div>
<div class="MainImage">
<img src="../path_info/<?php echo $now_viewing."/$mainImage"; ?>" alt="" <?php echo $imageSize[3]; ?>/>
</div><!--END <MainImage-->
<div class="GalleryNav">
<div id="Crumbs_Left">
<p>Displaying item x of y</p>
</div>
<div id="Crumbs_Right">
<p id="Crumbs_Right"><< Previous Next >></p>
</div>
</div><!--END <GalleryNav-->