From 58e8caf2afb3ea054f83999fb0698720a1a58738 Mon Sep 17 00:00:00 2001 From: John Crepezzi Date: Sat, 5 Feb 2011 22:19:57 -0500 Subject: Added documentation for changes to DB_result --- user_guide/database/results.html | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'user_guide/database') 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 } +

You can also pass a string to result() which represents a class to instantiate for each result object (note: this class must be loaded)

+ + + $query = $this->db->query("SELECT * FROM users;");
+
+ foreach ($query->result('User') as $user)
+ {
+    echo $row->name; // call attributes
+    echo $row->reverse_name(); // or methods defined on the 'User' class
+ } +
+

result_array()

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:

@@ -133,6 +145,15 @@ Query Results $row = $query->row(5); +

You can also add a second String parameter, which is the name of a class to instantiate the row with:

+ + + $query = $this->db->query("SELECT * FROM users LIMIT 1;");
+
+ $query->row(0, 'User')
+ echo $row->name; // call attributes
+ echo $row->reverse_name(); // or methods defined on the 'User' class
+

row_array()

@@ -235,4 +256,4 @@ Next Topic:  Query Helper Functions - \ No newline at end of file + -- cgit v1.2.3-24-g4f1b