Merge branch 'develop' of https://github.com/EllisLab/CodeIgniter into develop
diff --git a/system/database/DB_query_builder.php b/system/database/DB_query_builder.php
index a734603..0d04213 100644
--- a/system/database/DB_query_builder.php
+++ b/system/database/DB_query_builder.php
@@ -2557,18 +2557,22 @@
 			return;
 		}
 
-		foreach ($this->qb_cache_exists as $val)
+		$parts = array_unique($this->qb_cache_exists); // select, from, etc.
+
+		foreach ($parts as $val)
 		{
 			$qb_variable	= 'qb_'.$val;
 			$qb_cache_var	= 'qb_cache_'.$val;
 
-			if (count($this->$qb_cache_var) > 0)
+			$qb_new = $this->$qb_cache_var;
+
+			foreach ($this->$qb_variable as $qb_var)
 			{
-				foreach ($this->$qb_cache_var as &$cache_var)
-				{
-					in_array($cache_var, $this->$qb_variable, TRUE) OR $this->{$qb_variable}[] = $cache_var;
-				}
+			 	in_array($qb_var, $qb_new, TRUE) OR $qb_new[] = $qb_var;
 			}
+			
+			$this->$qb_variable = $qb_new;
+
 		}
 
 		// If we are "protecting identifiers" we need to examine the "from"
diff --git a/user_guide_src/source/database/query_builder.rst b/user_guide_src/source/database/query_builder.rst
index 65609c1..5e0dcb4 100644
--- a/user_guide_src/source/database/query_builder.rst
+++ b/user_guide_src/source/database/query_builder.rst
@@ -68,7 +68,7 @@
 	// Produces string: SELECT * FROM mytable
 
 The second parameter enables you to set whether or not the query builder query
-will be reset (by default it will be—just like `$this->db->get()`)::
+will be reset (by default it will be reset, just like when using `$this->db->get()`)::
 
 	echo $this->db->limit(10,20)->get_compiled_select('mytable', FALSE);
 	// Produces string: SELECT * FROM mytable LIMIT 20, 10
@@ -76,7 +76,7 @@
 
 	echo $this->db->select('title, content, date')->get_compiled_select();
 
-	// Produces string: SELECT title, content, date FROM mytable
+	// Produces string: SELECT title, content, date FROM mytable LIMIT 20, 10
 
 The key thing to notice in the above example is that the second query did not
 utilize `$this->db->from()`_ and did not pass a table name into the first
@@ -1055,4 +1055,4 @@
 	$data = $this->db->get()->result_array();
 
 	// Would execute and return an array of results of the following query:
-	// SELECT field1, field1 from mytable where field3 = 5;
\ No newline at end of file
+	// SELECT field1, field1 from mytable where field3 = 5;