require "lib.php"; //db connection info $dbh = openDb(); $page = (isset($_GET['p']) && is_numeric($_GET['p'])) ? $_GET['p'] : 1; //set page variable $pageSize = 9; //set number of pictures per page $maxPages = getCount($dbh, $pageSize); $endID = $pageSize * $page; $startID = $endID - $pageSize; $gallery = getGallery($dbh, $startID, $pageSize); $entries = array(); array_push($entries, null); $div_one = array(); $div_two = array(); $div_three = array(); foreach ($gallery as $photo) { $entry = array('id' => $photo['id'], 'title' => $photo['title'], 'description' => $photo['description'], 'thumb' => $photo['thumb_uri'], 'full' => $photo['full_uri']); array_push($entries, $entry); } $counted = count($entries); $sets = (int) ($counted / 3); //echo $counted . "-" . $sets; for ( $i = 0; $i <= $sets; $i += 1 ) { array_push($div_one, $entries[(($i*3) + 1)]); array_push($div_two, $entries[(($i*3) + 2)]); array_push($div_three, $entries[(($i*3) + 3)]); } //print_r($div_one); ?>