title: Image Gallery -- select image which displays first
body: <p>I have photo gallery based on jQuery scrip[t from: <a href="http://coffeescripter.com/code/ad-gallery/" rel="nofollow">http://coffeescripter.com/code/ad-gallery/</a>.</p>
  
  <p>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.</p>
  
  <p>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.</p>
  
  <p>Here is some code, which I have so far:</p>
  
  <pre><code>/* galleries.php */
      &lt;?php
          $idg = $_GET["idg"];
          if (file_exists(GALLERY.'galleries.php') &amp;&amp; $idg == '') 
          {
              require_once(GALLERY.'list_galleries.php');
          }
          else if (file_exists(GALLERY.'galleries.php') &amp;&amp; $idg != '' )
          {
              require_once(GALLERY.'view_gallery.php');
          }
      ?&gt;
  </code></pre>
  
  <p>/* list_galleries.php */</p>
  
  <pre><code>&lt;?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 '&lt;table class="galleryTable"&gt;';
          echo '&lt;tr &gt;';
          echo '&lt;td colspan="4"&gt;';
          echo '&lt;a href="?p=13&amp;idg='.$idg.'" class="galleryName" &gt;'.$galName.'&lt;/a&gt;';
          echo '&lt;/td&gt;';
          echo '&lt;td class="galleryCount"&gt;';
          echo '&lt;/td&gt;';
          echo '&lt;/tr&gt;';
          echo '&lt;tr class="galleryRow"&gt;';
  
          while ($row_gal_con = @mysql_fetch_array($res_gal_con)){
  
              $desc = $row_gal_con["desc"];
              $img = $row_gal_con["img"];
  
              echo '&lt;td class="galleryCell"&gt;';
                              echo '&lt;a href="?p=13&amp;idg='.$idg.'"&gt;&lt;img src="'.GALLERY_DIR.'min/'.$img.'" alt="'.$desc.'" /&gt;&lt;/a&gt;';
              echo '&lt;/td&gt;';
  
          }
          echo '&lt;/tr&gt;';
          echo '&lt;/table&gt;';
      }
  
  ?&gt;
  </code></pre>
  
  <hr>
  
  <p>I have found proper solution based on tips from <a href="http://webdev.plentyinfo.com/tag/ad-gallery/" rel="nofollow">http://webdev.plentyinfo.com/tag/ad-gallery/</a></p>