PHP mysql查询2 OR和1 AND

时间:2016-08-29 07:10:17

标签: php

$query = "SELECT * FROM tbl_country WHERE language='$lang' AND country_name LIKE '%".$_POST["query"]."%' OR country_second LIKE '%".$_POST["query"]."%'";  

以上不起作用。我想要它在2个字段(作品)中搜索,但是基于我设置的语言。但它只是跳过lang部分

1 个答案:

答案 0 :(得分:0)

试试这个

$search = $_POST["query"];
if(empty($search))
{
    echo "Search filed is empty";
}
elseif (empty($lang)) {
    echo "Lang filed is empty";
}
else
{
    $query = "SELECT * FROM tbl_country WHERE language='$lang' AND 
                        (country_name LIKE '%$search%' OR country_second LIKE '%$search%') ";
}

使用()

换行