我正在尝试根据用户团队显示搜索结果。只有当我按客户名称搜索但是当我通过home_phone搜索时它才显示其他团队的记录
$query = "SELECT COUNT(*) as num FROM $tableName WHERE team = '".$team."' AND customer_name LIKE '%".$srcquery."%' OR home_phone LIKE '%".$srcquery."%' OR alt_phone LIKE '%".$srcquery."%' ORDER BY id DESC";
$total_pages = mysql_fetch_array(mysql_query($query));
$total_pages = $total_pages[num];
// Get page data
$query1 = "SELECT * FROM $tableName WHERE team = '".$team."' AND customer_name LIKE '%".$srcquery."%' OR home_phone LIKE '%".$srcquery."%' OR alt_phone LIKE '%".$srcquery."%' ORDER BY id DESC";
$result = mysql_query($query1);
感谢您的帮助
答案 0 :(得分:0)
在AND
之后使用括号:
$query = "SELECT COUNT(*) as num FROM $tableName WHERE team = '".$team."' AND (customer_name LIKE '%".$srcquery."%' OR home_phone LIKE '%".$srcquery."%' OR alt_phone LIKE '%".$srcquery."%') ORDER BY id DESC";
注意:所有OR
语句都应在括号内。