Sooo! Well, the title should say most of it. Are there any way to check if $this->db-where('stuff', $data)
has been set previously?
I could go out and make a bunch of testing of my own code (flags ect...), but I would like to know if anyone has knowledge of some fast and easy way to do it!
Thanks in advance!
[EDIT - 24-Apr-14] It's my own code. I have to variable that can be null
, String
or an array
. They are $categories
and $budget
. So if budget is set to 100$
and category is set to stuff
then I will need to use db->or_where
, but if only one of them is set, I need only to use db->where
. In this case it is quite simple just to check if first is set, but what if more values are used? I hope you get the point :)
Yes you can easily determine whether a where clause is set or not. In CodeIgniter the Active Record class stores the wheres in an array called ar_where
. You can use this array to determine if any where clauses are set or not.
For example check the following code snippet :
$this->db->select()
->from("foo")
->where('bar',NULL);
$this->db->or_where('xyz',NULL);
print_r(sizeof($this->db->ar_where));
The following will output a value of 2
. So you can use this array to check for your result.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.