Added ability to get data in an order
This commit is contained in:
parent
55922ed5cc
commit
2351c688a7
14
db-mysql.php
14
db-mysql.php
|
@ -47,7 +47,7 @@ class db
|
||||||
}
|
}
|
||||||
|
|
||||||
//Daten holen
|
//Daten holen
|
||||||
public function get($where = [], $link = 'AND')
|
public function get($where = [], $link = 'AND', $orderby = 'id', $order = 'ASC')
|
||||||
{
|
{
|
||||||
if (isset($this->col))
|
if (isset($this->col))
|
||||||
{
|
{
|
||||||
|
@ -82,7 +82,10 @@ class db
|
||||||
|
|
||||||
//print_r($whereAr);
|
//print_r($whereAr);
|
||||||
|
|
||||||
$stmt = $this->dbh->prepare('SELECT * FROM ' . $this->prefix . $this->col . $whereCl);
|
//Order
|
||||||
|
$orderstmt = 'ORDER BY '.$orderby.' '.$order;
|
||||||
|
|
||||||
|
$stmt = $this->dbh->prepare('SELECT * FROM `' . $this->prefix . $this->col .'`' . $whereCl.$orderstmt);
|
||||||
$stmt->execute($whereAr);
|
$stmt->execute($whereAr);
|
||||||
|
|
||||||
$all = [];
|
$all = [];
|
||||||
|
@ -143,7 +146,6 @@ class db
|
||||||
$i++;
|
$i++;
|
||||||
}
|
}
|
||||||
$stmt .= ') VALUES (' . $valCnt . ')';
|
$stmt .= ') VALUES (' . $valCnt . ')';
|
||||||
//echo $stmt;
|
|
||||||
|
|
||||||
$insert = $this->dbh->prepare($stmt);
|
$insert = $this->dbh->prepare($stmt);
|
||||||
return $insert->execute($vals);
|
return $insert->execute($vals);
|
||||||
|
@ -297,4 +299,10 @@ class db
|
||||||
$this->data = '';
|
$this->data = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Query
|
||||||
|
public function query($query)
|
||||||
|
{
|
||||||
|
$STH = $this->dbh->prepare($query);
|
||||||
|
return $STH->execute();
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -37,7 +37,7 @@ All data is available via `$db->data`.
|
||||||
|
|
||||||
### Syntax
|
### Syntax
|
||||||
|
|
||||||
`$db->get($where = [], $link = 'AND')`
|
`$db->get($where = [], $link = 'AND', $orderby = 'id', $order = 'ASC')`
|
||||||
|
|
||||||
`$where`
|
`$where`
|
||||||
An array to return specific data. If provided, only data which matches is returnend. Scheme: `['key' => 'value']`.
|
An array to return specific data. If provided, only data which matches is returnend. Scheme: `['key' => 'value']`.
|
||||||
|
@ -49,6 +49,9 @@ All data is available via `$db->data`.
|
||||||
|
|
||||||
To see it in action, take a look at `example.php` or the "Examples"-Section at the bottom of this document.
|
To see it in action, take a look at `example.php` or the "Examples"-Section at the bottom of this document.
|
||||||
|
|
||||||
|
`$orderby`
|
||||||
|
Will sort the Output with this column ascending or descending as specified in `$order`.
|
||||||
|
|
||||||
## insert()
|
## insert()
|
||||||
|
|
||||||
Inserts data provided via `$db->data` or directly via the function.
|
Inserts data provided via `$db->data` or directly via the function.
|
||||||
|
|
Loading…
Reference in New Issue