php


pagination limit images per page


So i want to make pagination, for now i don't know how to limit the images per page. I am using glob to get all the image files showing up, but i should limit them to be able use the pagination. I i had a databse then i would know how to limit them, but when they are in folder, dont know actualy. Any help with that ?
<?php
$files = glob("img/*.*");
for ($i=1; $i<count($files); $i++){
$image = $files[$i];
//print $image ."<br />";
echo '<img src="'.$image .'" alt="Random image" />';
}
$per_page = 9;
$pages = ceil(count($files)/$per_page);
$page = $_GET['page'];
if(!isset($_GET['page'])){
header("location: index.php?page=1");
}else{
$page = $_GET['page'];
}
//$start = (($page)*$per_page);
for($number=1;$number<=$pages;$number++)
{
echo ''.$number.'';
}
echo "<br>Current page: $page";
?>
UPDATE:
When i change code to this, 4 images not showing up.. why its like that?
$per_page = 12;
$page = $_GET['page'];
$start = (($page -1)*$per_page);
$files = array_slice(glob("img/*.*"), $start, $per_page);

Related Links

How to add a link to comment form in comment count
Trying to make a bootstrap carousel slide dynamic with a database using php
Is it possible to retrieve the alpha value of a pixel of a PNG file in the 0-255 range?
A non well formed numeric value encountered - Can not reproduce
PHP Prepared statements - Failing to retrieve the string from the database
Rewrite URL with multiple unset query parameters .htaccess
Opinion about using SESSION with PHP
Hiding WooCommerce Categories that don't have any products in them?
Symfony 3 - How to render and handle the same form in multiple actions in multiple controllers without duplicating too much code
Insert iteration data into database
php converting string to time issue in year [duplicate]
Installing a laravel app on ec2 with lamp set up
Get all possible combinations from 3 categories in MySQL
PHP - Decrypt - OpenSSL
Verifying and then displaying data from a database in HTML using php on click of a button
How to write sql query in wordpress page

Categories

HOME
opengl
webview
events
apple-push-notifications
yaml
angular-ui-grid
mathematical-optimization
cypher
google-sheets-query
clone
position
tup
anchor
buffer
amazon-elb
google-cloud-logging
user-defined-types
string-formatting
codefluent
renderscript
infrared
pfobject
clr
adminlte
gollum-wiki
connection-refused
intel
firemonkey-style
dragula
jstree
jpa-2.1
sap-lumira
ccavenue
pyspark-sql
boolean-logic
splunk-query
matlab-app-designer
snap-framework
caesar-cipher
shapeless
des
love2d
jade4j
forms-authentication
mars-simulator
sbjson
right-click
grunt-contrib-watch
pyttsx
notesview
zend-form
bit-shift
wysihtml5
dredd
rm
brightscript
nusoap
amazon-elastic-beanstalk
emf-compare
hmmlearn
gapi
boost-compute
scheduledexecutorservice
visual-studio-monaco
jsf-2.3
svnserve
django-testing
android-syncadapter
gulp-uglify
seadragon
android-expansion-files
android-mapview
green-threads
phpredis
webproject
python-curses
html-escape-characters
google-hangouts
iodocs
ecos
full-text-indexing
category-theory
tabletools
infinite
san
sql-view
stty
django-facebook
objective-c-runtime
donut-chart
proc-open
smartfox
towers-of-hanoi
image-formats
msinfo32
kaazing
hardcode
opends
litespeed
qtextbrowser
groovy-console
kernel32
simile
jmenu
mongrel2
downgrade
ios-4.2
.net-client-profile
datagridcolumn
comment-conventions
levels

Resources

Database Users
RDBMS discuss
Database Dev&Adm
javascript
java
csharp
php
android
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App