diff options
author | Derek Allard <derek.allard@ellislab.com> | 2007-12-19 00:55:06 +0100 |
---|---|---|
committer | Derek Allard <derek.allard@ellislab.com> | 2007-12-19 00:55:06 +0100 |
commit | 80dd702d4c46552a3d1f94c5083c83eeff333b45 (patch) | |
tree | b51f9ef9dfb3b1ff2939caf81d65c3f89947b3dd /system | |
parent | 6ddb5a17ae1a0a75ca75f846dbb7d3a98f1902a3 (diff) |
Added where_in() to Active Record.
Diffstat (limited to 'system')
-rw-r--r-- | system/database/DB_active_rec.php | 40 |
1 files changed, 37 insertions, 3 deletions
diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index e8059ab76..c3279e8c3 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -41,6 +41,8 @@ class CI_DB_active_record extends CI_DB_driver { var $ar_order = FALSE;
var $ar_orderby = array();
var $ar_set = array();
+ var $ar_wherein = array();
+
/**
@@ -240,9 +242,41 @@ class CI_DB_active_record extends CI_DB_driver { }
return $this;
}
-
-
-
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Where_in
+ *
+ * Generates a WHERE field IN ('item', 'item') SQL query
+ *
+ * @access public
+ * @param string The field to search
+ * @param array The values searched on
+ * @param string
+ * @return object
+ */
+ function where_in($key = NULL, $values = NULL, $type = 'and')
+ {
+ if ($key === NULL || !is_array($values))
+ {
+ return;
+ }
+
+ $type = (strtolower($type) == 'or') ? ' OR ' : ' AND ';
+
+ foreach ($values as $value)
+ {
+ $this->ar_wherein[] = $this->escape($value);
+ }
+
+ $prefix = (count($this->ar_where) == 0) ? '' : $type;
+
+ $this->ar_where[] = $prefix.$key. " IN (" . implode(", ", $this->ar_wherein) . ") ";
+
+ return $this;
+ }
+
// --------------------------------------------------------------------
/**
|