我正在对事件数据库进行搜索的查询存在问题。目的是关于运动,其结构是:
id_event event_sport event_city
1 10 153
2 12 270
3 09 135
Run Code Online (Sandbox Code Playgroud)
桌上运动就像:
sport_id sport_name
1 Basketball
Run Code Online (Sandbox Code Playgroud)
表格城市为:
city_id city_name
1 NYC
Run Code Online (Sandbox Code Playgroud)
事情变得复杂了,因为我的事件表如下:
id_event event_sport event_city
1 10,12 153,270
2 7,14 135,271
3 8,12 143,80
Run Code Online (Sandbox Code Playgroud)
而且我有一个多输入搜索表单,以便人们可以在自己的城市中搜索多个体育项目或多个城市的活动。我正在使用选择
例如,来自“选择”的搜索结果是:
City = 153,270 (if user selected more than one city)
Sport = 12 (if user only selected one sport, can be "9,15")
Run Code Online (Sandbox Code Playgroud)
因此,我需要在同一列中搜索城市和体育的多个值,并用逗号分隔,并且知道有时,如果用户输入的值不多,我们只能搜索一个值。
我当前的查询是:
SELECT * FROM events e
LEFT JOIN cities c ON e.event_city=c.city_id
LEFT JOIN sports s ON e.event_sport=s.sport_id …Run Code Online (Sandbox Code Playgroud) mysql ×1