mkas
mkas

Reputation: 513

Image Gallery -- select image which displays first

I have photo gallery based on jQuery scrip[t from: http://coffeescripter.com/code/ad-gallery/.

Images are stored in mySQL database. I have a page with list of galleries, which displays first five images from each gallery. Clicking at any of image moves to gallery and starts displaying from first image.

I would like to do that in a such way: if user clicks on second image, displaying should start from second image, if user clicks on third image, displaying should start from third image etc.

Here is some code, which I have so far:

/* galleries.php */
    <?php
        $idg = $_GET["idg"];
        if (file_exists(GALLERY.'galleries.php') && $idg == '') 
        {
            require_once(GALLERY.'list_galleries.php');
        }
        else if (file_exists(GALLERY.'galleries.php') && $idg != '' )
        {
            require_once(GALLERY.'view_gallery.php');
        }
    ?>

/* list_galleries.php */

<?php

    $sql_gal = "SELECT id_g, nazwa FROM page_gallery WHERE widok=1";
    $res_gal = @mysql_query($sql_gal);
    $n = mysql_num_rows($res_gal);

    while ($row_gal = @mysql_fetch_array($res_gal)){

        $galName = $row_gal["nazwa"];

        $idg = $row_gal["id_g"];

        $sql_gal_con = "SELECT desc, img FROM page_gallery_con
            WHERE id_g='$idg' ORDER BY order ASC LIMIT 5";
        $res_gal_con = @mysql_query($sql_gal_con);


        echo '<table class="galleryTable">';
        echo '<tr >';
        echo '<td colspan="4">';
        echo '<a href="?p=13&idg='.$idg.'" class="galleryName" >'.$galName.'</a>';
        echo '</td>';
        echo '<td class="galleryCount">';
        echo '</td>';
        echo '</tr>';
        echo '<tr class="galleryRow">';

        while ($row_gal_con = @mysql_fetch_array($res_gal_con)){

            $desc = $row_gal_con["desc"];
            $img = $row_gal_con["img"];

            echo '<td class="galleryCell">';
                            echo '<a href="?p=13&idg='.$idg.'"><img src="'.GALLERY_DIR.'min/'.$img.'" alt="'.$desc.'" /></a>';
            echo '</td>';

        }
        echo '</tr>';
        echo '</table>';
    }

?>

I have found proper solution based on tips from http://webdev.plentyinfo.com/tag/ad-gallery/

Upvotes: 0

Views: 1693

Answers (1)

Awais Qarni
Awais Qarni

Reputation: 18006

just add a if condition to check if your $_GET variable is set or not. For example before your second query change your code like this

 if(isset($_GET['idg']))
 $idg=$_GET['idg'];
 else
 $idg = $row_gal["id_g"];

Upvotes: 1

Related Questions