Jump to content


Photo

Gallery Help


  • Please log in to reply
5 replies to this topic

#1 Nrees87

Nrees87
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 04 March 2006 - 06:19 PM

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:
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>';
    }
}

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.

#2 Hooker

Hooker
  • Members
  • PipPipPip
  • Advanced Member
  • 193 posts
  • LocationWales, UK

Posted 04 March 2006 - 06:22 PM

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

#3 Nrees87

Nrees87
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 04 March 2006 - 08:39 PM

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

#4 Hooker

Hooker
  • Members
  • PipPipPip
  • Advanced Member
  • 193 posts
  • LocationWales, UK

Posted 05 March 2006 - 03:43 AM

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

#5 Nrees87

Nrees87
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 05 March 2006 - 05:13 PM

My fault lol, I tried defining the same function twice in my code file. Fixed now, links work :D

#6 Hooker

Hooker
  • Members
  • PipPipPip
  • Advanced Member
  • 193 posts
  • LocationWales, UK

Posted 06 March 2006 - 05:55 AM

it looks really good, congrats on getting it done :)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users