Nrees87 Posted March 4, 2006 Share Posted March 4, 2006 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. Quote Link to comment Share on other sites More sharing options...
Hooker Posted March 4, 2006 Share Posted March 4, 2006 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 Quote Link to comment Share on other sites More sharing options...
Nrees87 Posted March 4, 2006 Author Share Posted March 4, 2006 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 Quote Link to comment Share on other sites More sharing options...
Hooker Posted March 5, 2006 Share Posted March 5, 2006 hrm, you seem to have a little error up there, if ya need anymore help post it here and ill check back later Quote Link to comment Share on other sites More sharing options...
Nrees87 Posted March 5, 2006 Author Share Posted March 5, 2006 My fault lol, I tried defining the same function twice in my code file. Fixed now, links work :D Quote Link to comment Share on other sites More sharing options...
Hooker Posted March 6, 2006 Share Posted March 6, 2006 it looks really good, congrats on getting it done :) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.