Jump to content

Archived

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

Nrees87

Gallery Help

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.

Share this post


Link to post
Share on other sites
have ya taken a look at this tutorial: [a href=\"http://www.phpfreaks.com/tutorials/73/0.php\" target=\"_blank\"]http://www.phpfreaks.com/tutorials/73/0.php[/a]?

i think it deffinately applies to your problem

Share this post


Link to post
Share on other sites
Thanks Hooker, helped a great deal. Problem solved - take a look [a href=\"http://www.mlcfreeriders.co.uk/gallery.php\" target=\"_blank\"]http://www.mlcfreeriders.co.uk/gallery.php[/a]

Thanks,
Nathan

Share this post


Link to post
Share on other sites
hrm, you seem to have a little error up there, if ya need anymore help post it here and ill check back later

Share this post


Link to post
Share on other sites
My fault lol, I tried defining the same function twice in my code file. Fixed now, links work :D

Share this post


Link to post
Share on other sites
it looks really good, congrats on getting it done :)

Share this post


Link to post
Share on other sites

×

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.