我在查询中添加LIKE
时出现此错误
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' OR agent_ip = 'Counter' OR port = 'Counter' OR 0home_ip_por' at line 45
我的代码是:
'.($search_field ?" AND home_id = '$search_field' OR user_id_main = '$search_field' OR home_path = '$search_field'
OR home_name = '$search_field'
OR user_id_main IN (SELECT `user_id` FROM `".$this->table_prefix."users` WHERE users_login = '$search_field')
OR user_id = '$search_field'
OR user_id IN (SELECT `user_id` FROM `".$this->table_prefix."users` WHERE users_login = '$search_field')
OR agent_ip = '$search_field' OR port = '$search_field'
" : '').
我需要将=
替换为LIKE
中的OR home_name = '$search_field'
答案 0 :(得分:0)
试试这个:
'.($search_field ?" AND home_id = '$search_field' OR user_id_main = '$search_field' OR home_path = '$search_field' OR home_name LIKE '%".$search_field."%' OR user_id_main IN (SELECT `user_id` FROM `".$this->table_prefix."users` WHERE users_login = '$search_field') OR user_id = '$search_field' OR user_id IN (SELECT `user_id` FROM `".$this->table_prefix."users` WHERE users_login = '$search_field') OR agent_ip = '$search_field' OR port = '$search_field'