esa*_*wan 0 php mysql duplicates
我在php中完成了三个餐厅搜索表.搜索可以选择按复选框状态按多种类型对其进行过滤.某些餐馆可能属于多种类型,并且在type_stack表中会有多个条目.
Table1 - **restaurant**
------+----------+----------
id + name + place
------+----------+----------
1 rest1 ny
2 rest2 la
3 rest3 ph
4 rest4 mlp
Table2 - **r_type**
------+----------+----------
id + name + code
------+----------+----------
1 type1 0
2 type2 1
3 type3 2
4 type4 3
Table3 - **type_stack**
------+----------+----------
id + rest_id + type
------+----------+----------
1 2 2
2 4 1
3 1 2
Run Code Online (Sandbox Code Playgroud)
我想让所有符合用户类型的餐厅都选中.但问题是1次多次到同一家餐馆.我只希望一次显示一行.
这是我的查询
SELECT restaurant.name, restaurant.place FROM restaurant, type_stack WHERE restaurant.id = type_stack.rest_id AND type_stack.type = '0' AND type_stack.type = '1' AND type_stack.type = '2' LIMIT 0 , 30
Run Code Online (Sandbox Code Playgroud)
查询是基于复选框状态进行的!在这种情况下,选择类型0,1和2.
将您的陈述更改为(您需要DISTINCT):
SELECT DISTINCT restaurant.name, restaurant.place FROM restaurant, type_stack WHERE restaurant.id = type_stack.rest_id AND type_stack.type = '0' AND type_stack.type = '1' AND type_stack.type = '2' LIMIT 0 , 30
Run Code Online (Sandbox Code Playgroud)