if (!defined('DB_HTML_EDIT')) define('DB_HTML_EDIT','Edit');
if (!defined('DB_HTML_DELETE')) define('DB_HTML_DELETE','Delete');
if (!defined('DB_HTML_NAV_TOP')) define('DB_HTML_NAV_TOP','<div class="nav" id="nav_top"></div>'.PHP_EOL);
+if (!defined('DB_TABLE_QUERY_NAME')) define('DB_TABLE_QUERY_NAME','_query_');
class table extends nb {
// Name, could be a select
if (stripos($name,'SELECT ')===0) {
#$temp = '_'.substr(md5($name),0,6);
- $temp = '_query_';
+ $temp = DB_TABLE_QUERY_NAME;
$this->db->conn->query("CREATE TEMPORARY TABLE $temp AS $name");
$name = $temp;
} elseif (preg_match('/\b(\.import|LOAD DATA|COPY|INSERT|REPLACE|DELETE|TRUNCATE|CREATE|DROP|ALERT)\b/',$name)) {
******************************************************************/
function rows($opt=array()) {
+ $select_count = ( (false and $this->db->type =='mysql') ? " SQL_CALC_FOUND_ROWS" : "");
//
// Select
//
- $sql = "SELECT".($this->db->type =='mysql' ? " SQL_CALC_FOUND_ROWS" : "")." *" . $this->select_extras();
- $sql .= " FROM ".$this->sql_name().$this->where_criterias($this->p(),$this->p('op'));
- $this->sql = $sql;
+ $sql = "SELECT$select_count *" . $this->select_extras();
+ $sql .= " FROM ".$this->sql_name();
+ $where = $this->where_criterias($this->p(),$this->p('op'));
+ $this->sql = $sql = $sql . $where;
$this->debug($sql,1);
if ($this->p('sort')) $sql .= ' ORDER BY '.$this->p('sort');
//
// Tot
//
- if ($this->db->type =='mysql') {
+ if ($select_count) {
$query = $this->db->conn->query('SELECT FOUND_ROWS()');
+
+# NB 06.01.16 } elseif ($where) {
+# NB 06.01.16 $sql_count = $sql;
+# NB 06.01.16 $sql_count = preg_replace('/ (ORDER|LIMIT) .*?$/s','',$sql_count);
+# NB 06.01.16 $sql_count = preg_replace('/^SELECT .*FROM/s','SELECT count(*) FROM ',$sql_count);
+# NB 06.01.16 $query = $this->db->conn->query($sql_count);
+
} else {
- $sql_count = $sql;
- $sql_count = preg_replace('/ (ORDER|LIMIT) .*?$/s','',$sql_count);
- $sql_count = preg_replace('/^SELECT .*FROM/s','SELECT count(*) FROM (',$sql_count).') count';
- $query = $this->db->conn->query($sql_count);
+ $query = $this->db->conn->query('SELECT count(*) FROM '.$this->sql_name());
+
}
if (!$query) {