summaryrefslogtreecommitdiffstats
path: root/user_guide
diff options
context:
space:
mode:
authoradmin <devnull@localhost>2006-10-01 05:38:04 +0200
committeradmin <devnull@localhost>2006-10-01 05:38:04 +0200
commitb2a9ceccdb85050cb494e6d0a98b0a49495d29bb (patch)
tree16307166046e516304e5d38a072b6e8534657927 /user_guide
parent0e42554740e2256eb9bf33bfb2f91788a99a1348 (diff)
Diffstat (limited to 'user_guide')
-rw-r--r--user_guide/database/examples.html41
-rw-r--r--user_guide/database/fields.html17
-rw-r--r--user_guide/database/results.html6
3 files changed, 59 insertions, 5 deletions
diff --git a/user_guide/database/examples.html b/user_guide/database/examples.html
index c58e9bb64..08051cadd 100644
--- a/user_guide/database/examples.html
+++ b/user_guide/database/examples.html
@@ -112,6 +112,28 @@ foreach ($query->result_array() as $row)<br />
<p>The above <dfn>result_array()</dfn> function returns an array of standard array indexes. Example: $row['title']</p>
+<h2>Testing for Results</h2>
+
+<p>If you run queries that might <strong>not</strong> produce a result, you are encouraged to test for a result first
+using the <dfn>num_rows()</dfn> function:</p>
+
+<code>
+$query = $this->db->query("YOUR QUERY");<br />
+<br />
+if ($query->num_rows() > 0)<br />
+{<br />
+&nbsp;&nbsp;&nbsp;foreach ($query->result() as $row)<br />
+&nbsp;&nbsp;&nbsp;{<br />
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo $row->title;<br />
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo $row->name;<br />
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo $row->body;<br />
+&nbsp;&nbsp;&nbsp;}<br />
+}
+</code>
+
+
+
+
<h2>Standard Query With Single Result</h2>
<code>$query = $this->db->query('SELECT name FROM my_table LIMIT 1');<br />
@@ -120,6 +142,19 @@ $row = $query->row();<br />
echo $row->name;<br />
</code>
+<p>The above <dfn>row()</dfn> function returns an <strong>object</strong>. Example: $row->name</p>
+
+
+<h2>Standard Query With Single Result (Array version)</h2>
+
+<code>$query = $this->db->query('SELECT name FROM my_table LIMIT 1');<br />
+<br />
+$row = $query->row_array();<br />
+echo $row->['name'];<br />
+</code>
+
+<p>The above <dfn>row_array()</dfn> function returns an <strong>array</strong>. Example: $row->['name']</p>
+
<h2>Standard Insert</h2>
@@ -146,7 +181,11 @@ foreach ($query->result() as $row)<br />
{<br />
&nbsp;&nbsp;&nbsp;&nbsp;echo $row->title;<br />
}</code>
-
+
+<p>The above <dfn>get()</dfn> function retrieves all the results from the supplied table.
+The <a href="active_record.html">Active Record</a> class contains a full compliment of functions
+for working with data.</p>
+
<h2>Active Record Insert</h2>
diff --git a/user_guide/database/fields.html b/user_guide/database/fields.html
index 260cd222f..83abe6327 100644
--- a/user_guide/database/fields.html
+++ b/user_guide/database/fields.html
@@ -94,6 +94,23 @@ foreach ($query->list_fields() as $field)<br />
</code>
+<h2>$this->db->field_exists();</h2>
+
+<p>Sometimes it's helpful to know whether a particular field exists befor performing an action.
+Returns a boolean TRUE/FALSE. Usage example:</p>
+
+<code>
+if ($this->db->field_exists('field_name', 'table_name'))<br />
+{<br />
+&nbsp;&nbsp; // some code...<br />
+}
+</code>
+
+<p>Note: Replace <em>field_name</em> with the name of the column you are looking for, and replace
+<em>table_name</em> with the name of the table you are looking for.</p>
+
+
+
<h2>$this->db->field_data();</h2>
<p>Returns an array of objects containing field information.</p>
diff --git a/user_guide/database/results.html b/user_guide/database/results.html
index 81abc50f8..75f4357b4 100644
--- a/user_guide/database/results.html
+++ b/user_guide/database/results.html
@@ -84,6 +84,8 @@ Query Results
&nbsp;&nbsp;&nbsp;echo $row->name;<br />
&nbsp;&nbsp;&nbsp;echo $row->body;<br />
}</code>
+
+ <p>The above <dfn>function</dfn> is an alias of <dfn>result_object()</dfn>.</p>
<p>If you run queries that might <strong>not</strong> produce a result, you are encouraged to test the result first:</p>
@@ -113,10 +115,6 @@ Query Results
&nbsp;&nbsp;&nbsp;echo $row['name'];<br />
&nbsp;&nbsp;&nbsp;echo $row['body'];<br />
}</code>
-
- <h2>result('array')</h2>
-
- <p>Identical to <dfn>$this->db->result_array()</dfn>.</p>
<h2>row()</h2>