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
5abe3177
Commit
5abe3177
authored
Aug 11, 2013
by
Alexander Butenko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added orderBy functionality
parent
4e3c1df0
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
0 deletions
+37
-0
MysqliDb.php
MysqliDb.php
+30
-0
readme.md
readme.md
+7
-0
No files found.
MysqliDb.php
View file @
5abe3177
...
...
@@ -42,6 +42,10 @@ class MysqliDb
* @var array
*/
protected
$_whereTypeList
;
/**
* Dynamic type list for order by condition value
*/
protected
$_orderBy
=
array
();
/**
* Dynamic type list for table data values
*
...
...
@@ -97,6 +101,7 @@ class MysqliDb
protected
function
reset
()
{
$this
->
_where
=
array
();
$this
->
_orderBy
=
array
();
$this
->
_bindParams
=
array
(
''
);
// Create the empty 0 index
unset
(
$this
->
_query
);
unset
(
$this
->
_whereTypeList
);
...
...
@@ -252,6 +257,21 @@ class MysqliDb
return
$this
;
}
/**
* This method allows you to specify multiple (method chaining optional) ORDER BY statements for SQL queries.
*
* @uses $MySqliDb->orderBy('id', 'desc')->orderBy('name', 'desc');
*
* @param string $whereProp The name of the database field.
* @param mixed $whereValue The value of the database field.
*
* @return MysqliDb
*/
public
function
orderBy
(
$orderByField
,
$orderbyDirection
)
{
$this
->
_orderBy
[
$orderByField
]
=
$orderbyDirection
;
return
$this
;
}
/**
* This methods returns the ID of the last inserted item
...
...
@@ -379,6 +399,16 @@ class MysqliDb
$this
->
_query
=
rtrim
(
$this
->
_query
,
' AND '
);
}
// Did the user call the "orderBy" method?
if
(
!
empty
(
$this
->
_orderBy
))
{
$this
->
_query
.=
" order by "
;
foreach
(
$this
->
_orderBy
as
$prop
=>
$value
)
{
// prepares the reset of the SQL query.
$this
->
_query
.=
$prop
.
" "
.
$value
.
", "
;
}
$this
->
_query
=
rtrim
(
$this
->
_query
,
', '
)
.
" "
;
}
// Determine if is INSERT query
if
(
$hasTableData
)
{
$pos
=
strpos
(
$this
->
_query
,
'INSERT'
);
...
...
readme.md
View file @
5abe3177
...
...
@@ -118,3 +118,10 @@ $results = $db
->
where
(
'title'
,
'MyTitle'
)
->
get
(
'tableName'
);
```
### Ordering method
```
php
$db
->
orderBy
(
"id"
,
"asc"
);
$db
->
orderBy
(
"name"
,
"Desc"
);
$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