}
- //
- // Tot
- //
- if ($select_count) {
- $query = $this->db->conn->query('SELECT FOUND_ROWS()');
-
- } elseif ($where) {
- $sql_count = $sql;
- $sql_count = preg_replace('/ (ORDER|LIMIT) .*?$/s','',$sql_count);
- $sql_count = preg_replace('/^SELECT .*FROM/s','SELECT count(*) FROM ',$sql_count);
- $query = $this->db->conn->query($sql_count);
+ if ($opt['is_html']) {
+ //
+ // Tot
+ //
+ if (true and !$where and !$limit) {
+ debug("Not using count(*)");
+ $query = $this->db->conn->query("SELECT $count");
+
+ } elseif ($select_count) {
+ $query = $this->db->conn->query('SELECT FOUND_ROWS()');
+
+ } elseif ($where) {
+ $sql_count = $sql;
+ $sql_count = preg_replace('/ (ORDER|LIMIT) .*?$/s','',$sql_count);
+ $sql_count = preg_replace('/^SELECT .*FROM/s','SELECT count(*) FROM ',$sql_count);
+ $query = $this->db->conn->query($sql_count);
- } else {
- $query = $this->db->conn->query('SELECT count(*) FROM '.$this->sql_name());
+ } else {
+ $query = $this->db->conn->query('SELECT count(*) FROM '.$this->sql_name());
- }
+ }
- if (!$query) {
- $err = $this->db->conn->errorInfo();
- $err[] = $sql;
- err(join(' | ',$err));
- return $err[0];
- }
+ if (!$query) {
+ $err = $this->db->conn->errorInfo();
+ $err[] = $sql;
+ err(join(' | ',$err));
+ return $err[0];
+ }
- $tot = $query->fetch(PDO::FETCH_COLUMN);
- $opt['tot'] = $tot;
- #if (!$tot) return;
+ $tot = $query->fetch(PDO::FETCH_COLUMN);
+ $opt['tot'] = $tot;
+ #if (!$tot) return;
- $opt['count'] = $count;
- $opt['limit'] = $limit;
- echo $this->{"rows_end_$format"}($opt);
+ $opt['count'] = $count;
+ $opt['limit'] = $limit;
+ echo $this->{"rows_end_$format"}();
- if ($opt['is_html']) echo '<div class="nav bottom">'
- .$this->nav($opt['count'],$opt['tot'],$opt['limit'])
- .'</div>'
- .PHP_EOL;
+ echo '<div class="nav bottom">'
+ .$this->nav($opt['count'],$opt['tot'],$opt['limit'])
+ .'</div>'.PHP_EOL
+ ;
+ }
$st->closeCursor();
/*-----------------------------------------------------------------
Yaml
-----------------------------------------------------------------*/
- function rows_begin_yaml() {
- return "---\n";
- }
-
- function rows_rec_yaml(&$row) {
- $yaml = yaml_emit($row);
- $yaml = preg_replace('/^---\n/','',$yaml);
- $yaml = preg_replace('/\n\.\.\.$/','',$yaml);
- $yaml = preg_replace('/^/m',' ',$yaml);
- return '- '.trim($yaml)."\n";
- }
-
- function rows_end_yaml() {
- return '';
- }
+ function rows_begin_yaml() { return "---\n"; }
+ function rows_rec_yaml(&$row) { return $this->yaml_encode($row); }
+ function rows_end_yaml() { return ''; }
/*-----------------------------------------------------------------
Xml
$yaml = yaml_emit($row);
$yaml = preg_replace('/^---\n/','',$yaml);
$yaml = preg_replace('/\n\.\.\.$/','',$yaml);
- return "--- \n".trim($yaml)."\n";
- return trim($yaml)."\n";
- $yaml = preg_replace('/^/m',' ',$yaml);
- return '- '.trim($yaml)."\n";
+ $yaml = trim($yaml);
+ if ($yaml === "---") return '' ;
+ if (preg_match('/^---\s*$/m',$yaml)) return '' ;
+ return "--- \n$yaml\n";
}
}