summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrey Andreev <narf@devilix.net>2015-03-16 16:00:33 +0100
committerAndrey Andreev <narf@devilix.net>2015-03-16 16:00:33 +0100
commit00e34370e1f235b09e49adfa28f21c8fa3a41778 (patch)
tree4680af17b7c7dfaa68bbf61586e3ee5a1dd7a454
parent7f310d63d61e9b334385ef5f6501129d685924ba (diff)
parent2f164058e3ffa429747e27b284f67f2e71809f52 (diff)
Merge pull request #3669 from yaoshanliang/develop
count_all_results() with $this->reset_select()
-rw-r--r--system/database/DB_query_builder.php9
-rw-r--r--user_guide_src/source/changelog.rst1
-rw-r--r--user_guide_src/source/database/query_builder.rst6
3 files changed, 14 insertions, 2 deletions
diff --git a/system/database/DB_query_builder.php b/system/database/DB_query_builder.php
index 79cbfb3ad..e5ffef2bb 100644
--- a/system/database/DB_query_builder.php
+++ b/system/database/DB_query_builder.php
@@ -1353,9 +1353,10 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
* returned by an Query Builder query.
*
* @param string
+ * @param bool the reset clause
* @return int
*/
- public function count_all_results($table = '')
+ public function count_all_results($table = '', $reset = TRUE)
{
if ($table !== '')
{
@@ -1366,7 +1367,11 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
$result = ($this->qb_distinct === TRUE)
? $this->query($this->_count_string.$this->protect_identifiers('numrows')."\nFROM (\n".$this->_compile_select()."\n) CI_count_all_results")
: $this->query($this->_compile_select($this->_count_string.$this->protect_identifiers('numrows')));
- $this->_reset_select();
+
+ if ($reset === TRUE)
+ {
+ $this->_reset_select();
+ }
if ($result->num_rows() === 0)
{
diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst
index 99e4de53a..7f6cafa95 100644
--- a/user_guide_src/source/changelog.rst
+++ b/user_guide_src/source/changelog.rst
@@ -192,6 +192,7 @@ Release Date: Not Released
- Methods ``insert_batch()`` and ``update_batch()`` now return an integer representing the number of rows affected by them.
- Methods ``where()``, ``or_where()``, ``having()`` and ``or_having()`` now convert trailing ``=`` and ``<>``, ``!=`` SQL operators to ``IS NULL`` and ``IS NOT NULL`` respectively when the supplied comparison value is ``NULL``.
- Added method chaining support to ``reset_query()``, ``start_cache()``, ``stop_cache()`` and ``flush_cache()``.
+ - Added an optional second to ``count_all_results()`` to disable resetting of QB values.
- :doc:`Database Results <database/results>` changes include:
diff --git a/user_guide_src/source/database/query_builder.rst b/user_guide_src/source/database/query_builder.rst
index 9b4694710..68ddca717 100644
--- a/user_guide_src/source/database/query_builder.rst
+++ b/user_guide_src/source/database/query_builder.rst
@@ -527,6 +527,12 @@ where(), or_where(), like(), or_like(), etc. Example::
$this->db->from('my_table');
echo $this->db->count_all_results(); // Produces an integer, like 17
+The second paramater is to disable resetting of QB values. Example::
+
+ echo $this->db->count_all_results('my_table'); // Produces an integer, like 25
+ $this->db->like('title', 'match');
+ echo $this->db->count_all_results(); // Produces an integer, like 17
+
**$this->db->count_all()**
Permits you to determine the number of rows in a particular table.