我有两个表,第一个是包含用户详细信息的用户表,第二个是存储了服务 ID 的服务表。
表用户:
id Name mail gender
-----------------------------------------
1 John john@gmail.com Male
2 Mike mike@gmail.com Male
3 Duke duke@gmail.com Male
4 Queen queen@gmail.com Female
餐桌服务:
id profile_email service
----------------------------
1 john@gmail.com 3
2 john@gmail.com 4
3 mike@gmail.com 3
4 mike@gmail.com 5
5 queen@gmail.com 3
6 queen@gmail.com 4
表单复选框:
<input type="checkbox" value="1" name="services[]" id="services1" /> Service 1
<input type="checkbox" value="2" name="services[]" id="services2" /> Service 2
<input type="checkbox" value="3" name="services[]" id="services3" /> Service 3
<input type="checkbox" value="4" name="services[]" id="services4" /> Service 4
<input type="checkbox" value="5" name="services[]" id="services5" /> Service 5
现在我的问题是如何加入这两个表以显示基于检查服务的过滤记录。
我正在尝试以下查询,但问题是显示重复行。请帮我。非常感谢你提前.m
$select = "SELECT a.*, b.services FROM users a LEFT JOIN services AS b ON b.profile_email = a.mail ";
if(isset($_REQUEST['services']))
{
$services_search = mysql_real_escape_string(implode(', ', $_REQUEST['services']));
$select .= " AND b.services IN ($services_search)";
}