simple oo php example:
<?php
<?php
class ImageDetails {
/**
* all image details you need from your db.
* use "mysql_fetch_object" to build your results as objects
*/
public function getName() {
return 'x';
// image name for example...
}
}
class ImageGallery {
private $list;
private $size;
/**
* @param array $list, list of images details
* @param int $size, number of gallery collumns
*/
public function __construct($list, $size = 3) {
$this->list = $list;
$this->size = $size;
}
public function show() {
$counter = 0;
echo '<table border="1">';
foreach ($this->list as $image) {
if ($counter == 0) { // open row
echo '<tr>';
}
$this->_printRow($image);
++$counter;
if ($counter == $this->size) { // close row
echo '</tr>';
$counter = 0;
}
}
if ($counter != 0) { // padding the table
$this->_paddTable($counter);
}
echo '</table>';
}
private function _printRow($image) {
// here you print the image in any form you want
echo '<td>' . $image->getName() . '</td>';
}
private function _paddTable($counter) {
for ($i=$counter ; $i<$this->size ; ++$i) {
echo '<td> </td>';
}
}
}
// 'list of your images (ImageDetails objects)
$list = array(new ImageDetails(), new ImageDetails(), new ImageDetails(), new ImageDetails(), new ImageDetails(), new ImageDetails(), new ImageDetails(), new ImageDetails(), new ImageDetails(), new ImageDetails());
$gallery = new ImageGallery($list);
$gallery->show();