Jump to content

Gallery Help


Nrees87

Recommended Posts

Hi there guys (and gals of course Wink ). I'm currently creating a website for a friend of mine. I've written a gallery page (really simple one) which just retrieves data from a MySQL database. What I'm trying to do now is to get it to automatically split the gallery into X amount of pages, each page with 20 images on it. For some reason I can't get my head around it.

So far I have this:
[code]
function new_display_gallery($img_dir,$cat,$page)
{  
    $query = "SELECT * FROM `mlc_gallery` WHERE `Category` = '" . $cat . "' ORDER BY `ItemID` ASC;";
    $result = mysql_query($query) or die(mysql_error());
    
    if(mysql_num_rows($result) == "0")
    {
        echo '<p><i>This Gallery is empty</i></p>';
    }
    else
    {
      
      $g_size = mysql_num_rows($result);
      //5 colums * 4 rows = 20 imgs per page
      $pages = ceil($g_size / 20);
      if($page == "1")
      {
          $query = "SELECT * FROM `mlc_gallery` WHERE `Category` = '" . $cat . "' LIMIT 1,20" ;
          $res = mysql_query($query) or die(mysql_error());
        $r = mysql_fetch_assoc($query);
      }
      elseif($page == "2")
      {
          $query = "SELECT * FROM `mlc_gallery` WHERE `Category` = '" . $cat . "' LIMIT 21,20" ;
          $res = mysql_query($query) or die(mysql_error());
        $r = mysql_fetch_assoc($query);
      }
      elseif($page == "3")
      {
          $query = "SELECT * FROM `mlc_gallery` WHERE `Category` = '" . $cat . "' LIMIT 41,20" ;
          $res = mysql_query($query) or die(mysql_error());
        $r = mysql_fetch_assoc($query);
      }
      echo '<div id="main" style="width: 512px;">';
      echo '<table id="display_thumbnails" cellpadding="0" cellspacing="0">';
      while($r_num <= 6)
      {
          echo '<tr>';
          while($c_num <= 6)
          {
            echo "<td><img src='./gallery/mlc/" . $r['File']. "' /></td>";
            $c_num++;
        }
        echo '</tr>';
        $r_num++;
      }
      echo '</table>';
      echo '</div>';
      echo '<div class="navigate_images"><p>Page ' . $page . ' of '    . $pages . '</p></div>';
    }
}
[/code]

It's driving me crazy because I've hit a complete mental block of how to do this.

Can anyone provide any help/ideas or possibly some example code?

Thanks in advance,
Nathan Rees.
Link to comment
https://forums.phpfreaks.com/topic/4095-gallery-help/
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.