CI_DB_active_record::count_all_results PHP Метод

count_all_results() публичный Метод

Generates a platform-specific query string that counts all records returned by an Active Record query.
public count_all_results ( $table = '' ) : string
Результат string
    function count_all_results($table = '')
    {
        if ($table != '') {
            $this->_track_aliases($table);
            $this->from($table);
        }
        $sql = $this->_compile_select($this->_count_string . $this->_protect_identifiers('numrows'));
        $query = $this->query($sql);
        $this->_reset_select();
        if ($query->num_rows() == 0) {
            return '0';
        }
        $row = $query->row();
        return $row->numrows;
    }

Usage Example

Пример #1
0
 /**
  * Return the number of results for the current query
  *
  */
 public function count()
 {
     //If data has already been selected return the row count
     if (sizeof($this->all()) > 0) {
         return sizeof($this->all());
     } else {
         $this->db->from($this->_table());
         return $this->db->count_all_results();
     }
 }