i can't get my head around this, being retarded.
say i want to have more than 2 pics per page on my pagination, how do i alter the variables below to slice the array for 10 per page?
say i want to have more than 2 pics per page on my pagination, how do i alter the variables below to slice the array for 10 per page?
Code:
//check to see if the page has been set
$page = (isset($_GET['page'])) ? (int)preg_replace('#[^0-9]#i','',$_GET['page']): 1;
$quantity = 2; //number per page
$list = scandir('image_gallery');
$list = array_slice($list, 2);
//Get the number of pages
$pages = ceil(count($list)/$quantity);
if ($page==1)
{
$files_to_display = array_slice($list, 0, $quantity);
}
else if ($page==2)
{
$files_to_display = array_slice($list, 2, $quantity);
}
else if ($page>2)
{
$files_to_display = array_slice($list, $page+$page-2, $quantity);
}
?>
<h1>Photo Gallery</h1>
<br />
<?php echo 'page:' . $page ?>
<?php
foreach($files_to_display as $file)
{
echo "<div class='file'><div class='image'><img src='image_gallery/$file'></div>$file</div>";
}
for ($i=1; $i <= $pages; $i++ )
{
echo "<a href='?page=$i'>$i</a> ";
}
?>
<br />