Fix count when there is a "group by" in the query (do not delete actual select).
This commit is contained in:
parent
a7cb44a04b
commit
fe98d94692
@ -25,7 +25,7 @@ class ModelMySQL {
|
|||||||
static protected $tableSufix = 's';
|
static protected $tableSufix = 's';
|
||||||
static protected $db;
|
static protected $db;
|
||||||
static protected $querySelect = [
|
static protected $querySelect = [
|
||||||
'select' => '*',
|
'select' => ['*'],
|
||||||
'where' => '',
|
'where' => '',
|
||||||
'from' => '',
|
'from' => '',
|
||||||
'leftJoin' => '',
|
'leftJoin' => '',
|
||||||
@ -83,7 +83,7 @@ class ModelMySQL {
|
|||||||
*/
|
*/
|
||||||
protected static function resetQuery() {
|
protected static function resetQuery() {
|
||||||
static::$querySelect = [
|
static::$querySelect = [
|
||||||
'select' => '*',
|
'select' => ['*'],
|
||||||
'where' => '',
|
'where' => '',
|
||||||
'from' => '',
|
'from' => '',
|
||||||
'leftJoin' => '',
|
'leftJoin' => '',
|
||||||
@ -104,7 +104,7 @@ class ModelMySQL {
|
|||||||
* Contiene la sentencia SQL.
|
* Contiene la sentencia SQL.
|
||||||
*/
|
*/
|
||||||
private static function buildQuery() {
|
private static function buildQuery() {
|
||||||
$sql = 'SELECT '.static::$querySelect['select'];
|
$sql = 'SELECT '.join(', ', static::$querySelect['select']);
|
||||||
|
|
||||||
if (static::$querySelect['from'] != '') {
|
if (static::$querySelect['from'] != '') {
|
||||||
$sql .= ' FROM '.static::$querySelect['from'];
|
$sql .= ' FROM '.static::$querySelect['from'];
|
||||||
@ -302,7 +302,7 @@ class ModelMySQL {
|
|||||||
$select[] = $db->real_escape_string($column);
|
$select[] = $db->real_escape_string($column);
|
||||||
}
|
}
|
||||||
|
|
||||||
static::$querySelect['select'] = join(', ', $select);
|
static::$querySelect['select'] = $select;
|
||||||
|
|
||||||
return new static();
|
return new static();
|
||||||
}
|
}
|
||||||
@ -612,7 +612,10 @@ class ModelMySQL {
|
|||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
public static function count() {
|
public static function count() {
|
||||||
static::$querySelect['select'] = 'count(*) as quantity';
|
if (static::$querySelect['select'] == ['*'])
|
||||||
|
static::$querySelect['select'] = ['count(*) as quantity'];
|
||||||
|
else
|
||||||
|
static::$querySelect['select'][] = 'count(*) as quantity';
|
||||||
$sql = static::buildQuery();
|
$sql = static::buildQuery();
|
||||||
$result = static::query($sql)->fetch_assoc();
|
$result = static::query($sql)->fetch_assoc();
|
||||||
return $result['quantity'];
|
return $result['quantity'];
|
||||||
|
Loading…
Reference in New Issue
Block a user