Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
PHP-MySQLi-Database-Class
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kulya
PHP-MySQLi-Database-Class
Commits
246e2751
Commit
246e2751
authored
Nov 08, 2015
by
Alexander Butenko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
dbobject: fix for pagination function
parent
3cd0b3eb
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
5 deletions
+15
-5
dbObject.md
dbObject.md
+10
-0
dbObject.php
dbObject.php
+5
-5
No files found.
dbObject.md
View file @
246e2751
...
...
@@ -285,6 +285,16 @@ Object could be easily converted to a json string or an array.
$userArray
=
$user
->
toArray
();
```
###Pagination
Use paginate() instead of get() to fetch paginated result
```
php
$page
=
1
;
// set page limit to 2 results per page. 20 by default
product
::
$pageLimit
=
2
;
$products
=
product
::
arraybuilder
()
->
paginate
(
$page
);
echo
"showing
$page
out of "
.
product
::
$totalPages
;
```
###Examples
Please look for a use examples in
<a
href=
'tests/dbObjectTests.php'
>
tests file
</a>
and test models inside the
<a
href=
'tests/models/'
>
test models
</a>
directory
dbObject.php
View file @
246e2751
...
...
@@ -80,13 +80,13 @@ class dbObject {
*
* @var int
*/
public
$pageLimit
=
20
;
public
static
$pageLimit
=
20
;
/**
* Variable that holds total pages count of last paginate() query
*
* @var int
*/
public
$totalPages
=
0
;
public
static
$totalPages
=
0
;
/**
* An array that holds insert/update/select errors
*
...
...
@@ -427,10 +427,10 @@ class dbObject {
* @return array
*/
private
function
paginate
(
$page
,
$fields
=
null
)
{
$offset
=
$this
->
pageLimit
*
(
$page
-
1
);
$offset
=
self
::
$
pageLimit
*
(
$page
-
1
);
$this
->
db
->
withTotalCount
();
$results
=
$this
->
get
(
Array
(
$
this
->
pageLimit
,
$offse
t
),
$fields
);
$this
->
totalPages
=
round
(
$this
->
db
->
totalCount
/
$this
->
pageLimit
);
$results
=
$this
->
get
(
Array
(
$
offset
,
self
::
$pageLimi
t
),
$fields
);
self
::
$totalPages
=
round
(
$this
->
db
->
totalCount
/
self
::
$
pageLimit
);
return
$results
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment