Welcome Guest, Not a member yet? Register   Sign In
Active Record Issue with Like/Where
#1

[eluser]Mischievous[/eluser]
Here is my code:
Code:
function products($term = NULL)
    {
        if(isset($term))
        {
            foreach($this->product_fields as $index => $field)
            {
                if($index == 0)
                {
                    $this->db->like($field, $term);
                } else {
                    $this->db->or_like($field, $term);
                }
            }
            //$this->db->group_by('product_sku.product_id');
            $this->db->join('product', 'product_sku.product_id = product.product_id');
            $this->db->where('product.pd_active', 1);
            $this->db->where('product_sku.sku_active', 1);
            $result = $this->db->get('product_sku');
            if($this->db->count_all_results() > 0 )
            {
                $request = $result->result_array();
                return $request;
            } else {
                return FALSE;
            }
        } else {
            return FALSE;
        }
    }
Here is my problem:
Its not taking the where statements into consideration? I've checked the database and the products i've requested are not active and yet it still comes up? like its totally disregarding the where statement all together because possible the like statements?
#2

[eluser]frist44[/eluser]
With query problems, I generally enable the profiler ($this->output->enable_profiler(TRUE)Wink and look at the query at the bottom. Copy/paste into a query manager and see the output. I screw around with the query until it produces the correct results and then modify the code to produce that query. That may seem trial by fire, but it works for me, maybe or may not help in your case.

Seeing what the actual generated SQL is seems very valuable to me.
#3

[eluser]Mischievous[/eluser]
Ok... well its going through with the query but the "or LIKE" statement is overiding it because its passing true for OR LIKE??? ERG... need a way around this...




Theme © iAndrew 2016 - Forum software by © MyBB