james182 Posted April 16, 2009 Share Posted April 16, 2009 trying to get my image gallery script working. the probelm is the setup of the images. i need to display like: 123 456 $limit = 6; // img per page $start = 1; $slice = 9; $img_category = "CV"; //$img_category = $_GET['img_category']; $query = "SELECT * FROM tbl_imagebank WHERE img_category = '$img_category' ORDER BY img_name ASC "; $result = mysql_query($query, $link) or die("pagination fatal error: ".mysql_error()); $totalrows = mysql_num_rows($result); if(!isset($_GET['pg']) ||!is_numeric($_GET['pg'])){ $page = 1; } else { $page = $_GET['pg']; } $numofpages = ceil($totalrows / $limit); $limitvalue = $page * $limit - ($limit); $query = "SELECT * FROM tbl_imagebank WHERE img_category = '$img_category' ORDER BY img_name ASC LIMIT $limitvalue, $limit "; $result = mysql_query($query, $link) or die("pagination fatal error: ".mysql_error()); echo "<table border='0' cellpadding='10' cellspacing='10'>"; $num = 0; while($r = mysql_fetch_array($result)){ $num = $num + 1; if($num % 2 == 0){ echo "<td valign='top' width='50%'>"; echo "<table class='product_display'>"; echo "<tr><td>"; echo "<a href='#' id='". $r["img_file"] ."' class='preview'><img src='". $r["img_file"] ."' width='100' border='0' /></a>"; echo "</td></tr>"; echo "</table>"; echo "</td></tr>"; }else{ echo "<tr><td valign='top' width='50%'>"; echo "<table class='product_display'>"; echo "<tr><td>"; echo "</td></tr>"; echo "</table>"; echo "</td>"; } } if($num % 2 != 0){ echo "</td></tr>"; } echo "</table>"; echo "<p>"; if($page!= 1){ $pageprev = $page - 1; echo '<a href="image_bank.php?pg='.$pageprev.'&img_category='.$img_category.'">PREV</a> - '; }else{ echo "PREV - "; } if (($page + $slice) < $numofpages) { $this_far = $page + $slice; } else { $this_far = $numofpages; } if (($start + $page) >= 10 && ($page - 10) > 0) { $start = $page - 10; } for ($i = $start; $i <= $this_far; $i++){ if($i == $page){ echo "<b>".$i."</b> "; }else{ echo '<a href="image_bank.php?pg='.$i.'&img_category='.$img_category.'">'.$i.'</a> '; } } if(($totalrows - ($limit * $page)) > 0){ $pagenext = $page + 1; echo ' - <a href="image_bank.php?pg='.$pagenext.'&img_category='.$img_category.'">NEXT</a>'; }else{ echo " - NEXT"; } echo "</p>"; Link to comment https://forums.phpfreaks.com/topic/154429-image-gallery-prob/ Share on other sites More sharing options...
schilly Posted April 17, 2009 Share Posted April 17, 2009 looks like your on the right track. i would do something like this: <?php echo "<table border='0' cellpadding='10' cellspacing='10'>"; $num = 0; while($r = mysql_fetch_array($result)){ if($num % 3 == 0) //if mod zero then start new row echo "<tr>"; $num++; echo "<td valign='top' width='33%'>"; echo "<table class='product_display'>"; echo "<tr><td>"; echo "<a href='#' id='". $r["img_file"] ."' class='preview'><img src='". $r["img_file"] ."' width='100' border='0' /></a>"; echo "</td></tr>"; echo "</table>"; echo "</td>"; if($num % 3 == 0) //if mod 0 then end row echo "</tr>"; } //fill in rest of table if you don't have enough pics for 3 per row while($num % 3 != 0){ $num++; echo "<td valign='top' width='33%'>"; echo "<table class='product_display'>"; echo "<tr><td>"; echo "<a href='#' id='". $r["img_file"] ."' class='preview'><img src='". $r["img_file"] ."' width='100' border='0' /></a>"; echo "</td></tr>"; echo "</table>"; echo "</td>"; $empty_flag = true; } //if it goes through the previous while then need to add closing tr tag if($empty_flag) echo "</tr>"; echo "</table>"; basically because you want 3 pics per row you have to do mod 3 instead of 2. Link to comment https://forums.phpfreaks.com/topic/154429-image-gallery-prob/#findComment-812062 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.