Welcome Guest, Not a member yet? Register   Sign In
help with SQL query
#1

[eluser]JanDoToDo[/eluser]
Hey guys.

Have this query:

"SELECT * FROM product_info AS p JOIN product_info_detail AS pd ON p.product_id = pd.product_id WHERE p.active = 1 AND pd.language_id = 2 AND (p.product_id LIKE '%".$term."%' OR pd.title LIKE '%".$term."%' OR pd.description LIKE '%".$term."%')"

and would like it in AR format

I tried:
Code:
$query = $this -> db -> from('product_info AS p')
                                    -> join('product_info_detail AS pd', 'p.product_id = pd.product_id')
                                    -> where('p.active', 1)
                                    -> where('pd.language_id', $lang)
                                    -> like('p.product_id', $term)
                                    -> or_like('pd.title', $term)
                                    -> or_like('pd.description', $term)
                                    -> get();
but it didnt work because i needed brackets around the like conditions as otherwise it doesnt pick up the language condition. Is there any way to do this?
#2

[eluser]danmontgomery[/eluser]
Code:
$esc_term = $this->db->escape_like_str($term);

$query = $this -> db -> from('product_info AS p')
    -> join('product_info_detail AS pd', 'p.product_id = pd.product_id')
    -> where('p.active', 1)
    -> where('pd.language_id', $lang)
    -> where('( pd.product_id LIKE "%' . $esc_term . '%" OR pd.title LIKE "%' . $esc_term . '%" OR pd.description LIKE "%' . $esc_term . '%" )', NULL, FALSE)
    -> get();




Theme © iAndrew 2016 - Forum software by © MyBB