Welcome Guest, Not a member yet? Register   Sign In
Limit on rows
#1

[eluser]alberto24[/eluser]
Hi - I am struggling with an issue... I want to pull say 1,000 images from a database - I can do this part.

Where I am stuck is that I want to show 5 images on each line then 5 on the next and so on. I assume I can use an html table but how do I set the view to show 5 then break to a new table row?

Also - I'd like to do a pagination - is there a good tutorial for this? I've read a few that seem to work a bit differently.

Thanks!
#2

[eluser]Dam1an[/eluser]
If you use the HTML table class you can pass it an array of data (the images in this case) and set to to do 5 columns (see the make_columns function)

As for the pagination, a good place to start is also the user guide, with a tutorials here

Hope this helps Smile
#3

[eluser]alberto24[/eluser]
thank you for the quick reply - will look into the html class
#4

[eluser]alberto24[/eluser]
not sure that html table class will work - in the db I have 1.jpg, 2.jpg, etc. I need it to include an img tag around that so images display. I also want the images to be clickable to the page for that image.

will keep looking...thanks
#5

[eluser]Dam1an[/eluser]
you could always just make the table yourself
Have a foreach look over the db results, and have a counter as well
If the counter modulo 5 is 0, start a new row and carry on as normal

Something like
Code:
$i = 0;
foreach($images as $image) {
  if($i % 5 == 0) {
    // end table row and start new one
  }
  $i++;
  
  // print the cell with image and anchor
}
#6

[eluser]learning_php[/eluser]
Hi,

Here is how I have done it for a basic Image Gallery loading images from a file not database, It's way from being perfect but it might give you a start:

Code:
<?php

$images = "thumbs/"; # Location of small versions
$big = "uploads/";
$cols   = 5; # Number of columns to display

if ($handle = opendir($images)) {
   while (false !== ($file = readdir($handle))) {
       if ($file != "." && $file != ".." && preg_match('/[.](jpg)|(gif)|(png)$/',$file)) {
           $files[] = $file;
       }
   }
   closedir($handle);
}

$colCtr = 0;

echo '<table width="100%" cellspacing="0"><tr>';

foreach($files as $file)
{
  if($colCtr %$cols == 0)
    echo '</tr><tr><td colspan="5"><hr /></td></tr><tr>';
  echo '<td align="center"><a href="'. $big . $file . '"><img src="' . $images . $file . '" /></a></td>';
  $colCtr++;
}

echo '</table>' . "\r\n";

?&gt;




Theme © iAndrew 2016 - Forum software by © MyBB