Welcome Guest, Not a member yet? Register   Sign In
qb_where has 2 arrays of conditions value escape
#1

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
I wrote my first program in 15 minutes. It took me 3 hours to keypunch it.

I wrote my first BASH script in 5 minutes. It took me a day to find out I had to put a . (period) in front of it to get it to execute.
Reply
#2

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

(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
I wrote my first program in 15 minutes. It took me 3 hours to keypunch it.

I wrote my first BASH script in 5 minutes. It took me a day to find out I had to put a . (period) in front of it to get it to execute.
Reply
#4

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.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB