Welcome Guest, Not a member yet? Register   Sign In
active record problem (and/or)
#1

[eluser]Unknown[/eluser]
hi, i'm new here and i have a proble using active record for a search function using like
my code:
Code:
function get_main_search()
    {
        $keyword = $this->uri->segment(3, 0);
        $this->db->like('itemName', $keyword);
        $this->db->where('instock <>', '9');
        $this->db->or_like('label', $keyword);
        $this->db->where('instock <>', '9');
        $this->db->or_like('labelname', $keyword);
        $this->db->where('instock <>', '9');
        $this->db->or_like('title', $keyword);
        $this->db->where('instock <>', '9');
        $this->db->orderby('itemName, title');
        $query = $this->db->get('items');
        return $query;
            }
it seems to ignore the instock <> 9 part of the query. this works when use a normal sql query instead of active class. am i missing something?

thanks for your time
diep
#2

[eluser]tim1965[/eluser]
Try and write the same query using standard sql, and see if you get the same result. If you do then its something to do with your logic. When i get these problems i break it down and start simple and gradually add the "ands" and compare the results until i find the piece that is breaking the query.




Theme © iAndrew 2016 - Forum software by © MyBB