public $extras;
public $format = 'json';
public $formats = [ 'table','div','csv','xml','json','yaml','sh','sql' ];
- public $limits = ['10','20','50','100','500','1000'];
+ public $limits = ['20','50','100','500','1000'];
+ public $limit;
# Classes
public $out;
# Pdo
$this->connect_init();
+ # Params
+ /*
+ if (empty($this->limit) and !empty($this->limits)) {
+ $this->limit = $this->limits[0];
+ }
+ if (empty($this->limit)) {
+ if ($this->p('paged')) {
+ $this->limit = ($this->limit * $this->p('paged')).','.$this->limit;
+ } elseif ($this->limit=$this->p('limit')) {
+ } else {
+ $this->limit = $this->limits[0];
+ }
+ }
+ */
+
# Extras must disapear - NB 29.03.16
if (!empty($this->extras)) self::bye($this->extras);
return true;
}
// Handle limit
- if ($this->p('limit')) {
+ if ($this->limit) {
- $limit = (int)$this->p('limit');
+ $limit = (int)$this->limit;
$i = empty($head) ? 1 : 0;
foreach ($rows as $k=>$v) {
public $show_url_sort = true;
public $show_header = true;
public static $params = [ 'db', 'table', 'limit', 'debug', 'action'
- , 'page', 'paged' # wordpress
+ # wordpress
+ , 'page', 'paged'
];
function __construct($name,$opt=[]) {
// Add others
foreach ($opt as $k => $v) { $this->$k = $v; }
+ if (empty($this->db()->limit)) {
+ if ($this->p('paged')) {
+ $this->db()->limit = ($this->db()->limit * $this->p('paged')).','.$this->db()->limit;
+ } elseif ($this->db()->limit=$this->p('limit')) {
+ }
+ }
+
# NB 22.12.16: TODEL
$this->show_header =
(bool)$this->p('header',$this->show_header)
}
-# NB 03.04.16 if ($this->p('db')) $params['db'] = $this->p('db');
$flat = [];
foreach ($params as $k=>$v) { $flat[] = $k.'='.urlencode($v); }
return $flat ? '?'. join('&',$flat) : '';
if (isset($this->orderby)) self::pdef('orderby',$this->orderby);
if (self::p('order')) self::pset('orderby',self::p('orderby').' '.self::p('order')); # from Wordpress
- if (self::p('paged')) {
- self::pset( 'limit', (self::p('limit') * self::p('paged')).','.self::p('limit') );
- }
//
// Select
if ($this->p('orderby')) $sql .= ' ORDER BY '.$this->p('orderby');
- if ($this->p('limit')) {
- $limit = $this->p('limit');
+ if ($limit = $this->db()->limit) {
$sql .= ' LIMIT '.$limit;
} else {
$limit = '';
//
// Get results
//
-# NB 28.03.16 $this->sql = $sql;
$this->debug(preg_replace('/[\r\n]+[ ]*/',' ',$sql),1);
# NB 03.09.16 $this->debug(preg_replace('/(,|FROM|WHERE|HAVING|GROUP|ORDER)/i',"\n\\1",$sql),1);
return [$sql,$where,$limit,$select_count];
}
public function rows(&$opt=[],$opt_by_val=null) {
+ if (empty($this->db()->limit)) {
+ $this->db()->limit = $this->db()->limits[0];
+ }
#
# Run query