diff options
author | Phil Sturgeon <email@philsturgeon.co.uk> | 2011-02-16 20:03:49 +0100 |
---|---|---|
committer | Phil Sturgeon <email@philsturgeon.co.uk> | 2011-02-16 20:03:49 +0100 |
commit | 33ed0f37b6b8f2223cd3362bf8fca28102ab67c6 (patch) | |
tree | 99c613720a2fd8541764bb6fc893e0da28fa269b /user_guide/database/results.html | |
parent | 154da11c5bb4b7dc5c225f4fa018852ee45cc6eb (diff) | |
parent | d8d1e24eee56d2466c91ecd72b3c8932eb3d0639 (diff) |
Merged CodeIgniter Core changes and integrated rob1's secure cookie change into my secure cookie change.
Diffstat (limited to 'user_guide/database/results.html')
-rw-r--r-- | user_guide/database/results.html | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/user_guide/database/results.html b/user_guide/database/results.html index 75cb190f9..e9a5cb4cf 100644 --- a/user_guide/database/results.html +++ b/user_guide/database/results.html @@ -98,6 +98,18 @@ Query Results } </code> + <p>You can also pass a string to result() which represents a class to instantiate for each result object (note: this class must be loaded)</p> + + <code> + $query = $this->db->query("SELECT * FROM users;");<br /> + <br /> + foreach ($query->result('User') as $user)<br /> + {<br /> + echo $row->name; // call attributes<br /> + echo $row->reverse_name(); // or methods defined on the 'User' class<br /> + } + </code> + <h2>result_array()</h2> <p>This function returns the query result as a pure array, or an empty array when no result is produced. Typically you'll use this in a foreach loop, like this:</p> @@ -133,6 +145,15 @@ Query Results <code>$row = $query->row(<dfn>5</dfn>);</code> + <p>You can also add a second String parameter, which is the name of a class to instantiate the row with:</p> + + <code> + $query = $this->db->query("SELECT * FROM users LIMIT 1;");<br /> + <br /> + $query->row(0, 'User')<br /> + echo $row->name; // call attributes<br /> + echo $row->reverse_name(); // or methods defined on the 'User' class<br /> + </code> <h2>row_array()</h2> @@ -235,4 +256,4 @@ Next Topic: <a href="helpers.html">Query Helper Functions</a> </div> </body> -</html>
\ No newline at end of file +</html> |