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
9bf6ab7d
Commit
9bf6ab7d
authored
Aug 11, 2013
by
Alexander Butenko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added groupBy method
parent
5abe3177
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
38 additions
and
3 deletions
+38
-3
MysqliDb.php
MysqliDb.php
+32
-3
readme.md
readme.md
+6
-0
No files found.
MysqliDb.php
View file @
9bf6ab7d
...
@@ -46,6 +46,10 @@ class MysqliDb
...
@@ -46,6 +46,10 @@ class MysqliDb
* Dynamic type list for order by condition value
* Dynamic type list for order by condition value
*/
*/
protected
$_orderBy
=
array
();
protected
$_orderBy
=
array
();
/**
* Dynamic type list for group by condition value
*/
protected
$_groupBy
=
array
();
/**
/**
* Dynamic type list for table data values
* Dynamic type list for table data values
*
*
...
@@ -262,8 +266,8 @@ class MysqliDb
...
@@ -262,8 +266,8 @@ class MysqliDb
*
*
* @uses $MySqliDb->orderBy('id', 'desc')->orderBy('name', 'desc');
* @uses $MySqliDb->orderBy('id', 'desc')->orderBy('name', 'desc');
*
*
* @param string $
whereProp
The name of the database field.
* @param string $
orderByField
The name of the database field.
* @param mixed $
whereValue The value of the database field
.
* @param mixed $
orderByDirection Order direction
.
*
*
* @return MysqliDb
* @return MysqliDb
*/
*/
...
@@ -273,6 +277,21 @@ class MysqliDb
...
@@ -273,6 +277,21 @@ class MysqliDb
return
$this
;
return
$this
;
}
}
/**
* This method allows you to specify multiple (method chaining optional) GROUP BY statements for SQL queries.
*
* @uses $MySqliDb->orderBy('id', 'desc')->groupBy('name', 'desc');
*
* @param string $groupByField The name of the database field.
*
* @return MysqliDb
*/
public
function
groupBy
(
$groupByField
)
{
$this
->
_groupBy
[]
=
$groupByField
;
return
$this
;
}
/**
/**
* This methods returns the ID of the last inserted item
* This methods returns the ID of the last inserted item
*
*
...
@@ -399,9 +418,19 @@ class MysqliDb
...
@@ -399,9 +418,19 @@ class MysqliDb
$this
->
_query
=
rtrim
(
$this
->
_query
,
' AND '
);
$this
->
_query
=
rtrim
(
$this
->
_query
,
' AND '
);
}
}
// Did the user call the "groupBy" method?
if
(
!
empty
(
$this
->
_groupBy
))
{
$this
->
_query
.=
" GROUP BY "
;
foreach
(
$this
->
_groupBy
as
$key
=>
$value
)
{
// prepares the reset of the SQL query.
$this
->
_query
.=
$value
.
", "
;
}
$this
->
_query
=
rtrim
(
$this
->
_query
,
', '
)
.
" "
;
}
// Did the user call the "orderBy" method?
// Did the user call the "orderBy" method?
if
(
!
empty
(
$this
->
_orderBy
))
{
if
(
!
empty
(
$this
->
_orderBy
))
{
$this
->
_query
.=
"
order by
"
;
$this
->
_query
.=
"
ORDER BY
"
;
foreach
(
$this
->
_orderBy
as
$prop
=>
$value
)
{
foreach
(
$this
->
_orderBy
as
$prop
=>
$value
)
{
// prepares the reset of the SQL query.
// prepares the reset of the SQL query.
$this
->
_query
.=
$prop
.
" "
.
$value
.
", "
;
$this
->
_query
.=
$prop
.
" "
.
$value
.
", "
;
...
...
readme.md
View file @
9bf6ab7d
...
@@ -125,3 +125,9 @@ $db->orderBy("id","asc");
...
@@ -125,3 +125,9 @@ $db->orderBy("id","asc");
$db
->
orderBy
(
"name"
,
"Desc"
);
$db
->
orderBy
(
"name"
,
"Desc"
);
$results
=
$db
->
get
(
'tableName'
);
$results
=
$db
->
get
(
'tableName'
);
```
```
### Grouping method
```
php
$db
->
groupBy
(
"name"
);
$results
=
$db
->
get
(
'tableName'
);
```
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