CodeIgniter Forums
qb_where has 2 arrays of conditions value escape - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forum-5.html)
+--- Forum: General Help (https://forum.codeigniter.com/forum-24.html)
+--- Thread: qb_where has 2 arrays of conditions value escape (/thread-75569.html)



qb_where has 2 arrays of conditions value escape - gmgj - 02-22-2020

I believe what I have to is some kind of reset, clearout, free, new something, but, I have not found it yet.

I do a query and it works fine.

The I do another query and it combines the old where with the new where


in the CI_DB_mysqli_driver Object
.....
I have this
[qb_where:protected] => Array
        (
            [0] => Array
                (
                    [condition] => categories.id =
                    [value] => '13'
                    [escape] => 1
                )

            [1] => Array
                (
                    [condition] => AND (JL_posts.title LIKE '%nerve%' AND JL_posts.title LIKE '%entrapment%' OR  JL_posts.body LIKE '%nerve%' AND JL_posts.body LIKE '%entrapment%' )
                    [value] =>
                    [escape] => 1
                )

        )


If I delete the [1] => Array , I think I will be okay

What is the CI way of doing this

What I see is that the 2 arrays are combined in the next query

[10] => SELECT *

FROM `JL_posts`

INNER JOIN `JL_posts_categories` ON `JL_posts`.`id`=`JL_posts_categories`.`post_id`

INNER JOIN `JL_categories` ON `JL_posts_categories`.`category_id`=`JL_categories`.`id`

WHERE `JL_categories`.`id` = '13'

AND (`JL_posts`.`title` LIKE '%nerve%' AND `JL_posts`.`title` LIKE '%entrapment%' OR  `JL_posts`.`body` LIKE '%nerve%' AND `JL_posts`.`body` LIKE '%entrapment%' )
        )
Huh


RE: qb_where has 2 arrays of conditions value escape - jreklund - 02-22-2020

Hi, can you post the actual code resulting in this result.


RE: qb_where has 2 arrays of conditions value escape - gmgj - 02-22-2020

(02-22-2020, 10:58 AM)jreklund Wrote: Hi, can you post the actual code resulting in this result.
Thanks for the reply.  The code is in 2 controllers and a large model.  The model includes code that I think should be in the controllers.  One of the controllers handled most of the page building, the other controller was a search.  The search controller called into the same model as the page.   
basically it was setup to pass in an area of values

in the model, it tried to differentiate between what was wanted by checking the array 'where" that was passed it.

if(isset($where['category_id'])){
$this->db->join($this->posts_categories_table,"{$this->_table}.id={$this->posts_categories_table}.post_id","INNER");
$this->db->join($this->categories_table,"{$this->posts_categories_table}.category_id={$this->categories_table}.id","INNER");
$this->db->where("{$this->categories_table}.id", $where['category_id']);
unset($where['category_id']);
}

if(isset($where['hidden_post_id'])){
$this->db->where_not_in("{$this->_table}.id", $where['hidden_post_id']);
unset($where['hidden_post_id']);
}

if(isset($where['keyword'])){
$this->db->like("{$this->_table}.title", $where['keyword'],'both');
 $this->db->like("{$this->_table}.body", $where['keyword'],'both');
unset($where['keyword']); // crash when deleted


....

foreach ($where as $key => $value) {
$this->db->where($key, $value);
}

The search controller did this
//$base_where = array_merge($base_where,array('keyword'=>$this->input->post('keyword')));

but, base_where was already set from a prior action - 

So i got rid of the array_merge and my problems went away


RE: qb_where has 2 arrays of conditions value escape - jreklund - 02-22-2020

Are you running the query with ->get() or similar? I can't see it in the code you just provided. As it only will reset when it's actually have been run.