Php 显示正确的mysql连接时出现问题

Php 显示正确的mysql连接时出现问题,php,mysql,concatenation,Php,Mysql,Concatenation,我有两个mysql表,它们链接在一起,我需要显示我的类别列表 表_故事 sid || title || time || hometext || associated 1 || test || 2010-07-19 || text---- || 8-14- topicid || topicname || slug 1 || car || car 4 || w

我有两个mysql表,它们链接在一起,我需要显示我的类别列表

表_故事

sid    ||   title   ||   time      ||  hometext  ||  associated
1      ||   test    ||  2010-07-19 ||  text----  ||  8-14-
topicid     ||  topicname  ||  slug
1           ||  car        ||  car  
4           ||  wall       ||  wall  
8           ||  benz       ||  benz  
14          ||  ford       ||  ford  
表格主题

sid    ||   title   ||   time      ||  hometext  ||  associated
1      ||   test    ||  2010-07-19 ||  text----  ||  8-14-
topicid     ||  topicname  ||  slug
1           ||  car        ||  car  
4           ||  wall       ||  wall  
8           ||  benz       ||  benz  
14          ||  ford       ||  ford  
现在,如果我使用此查询获取故事列表:

 LEFT JOIN table_topics AS nto ON 
 (CONCAT(' ',COALESCE(ns.associated,'-'),'-') LIKE CONCAT('%',nto.topicid,'-%'))
然后,输出将显示主题id为:8、4、14的故事

您可以看到,它将主题id4计算为与14

请注意,我无法更改mysql表结构,我应该找到解决此问题的方法,我将执行以下操作: 在“-”上拆分关联,检查主题id是否在结果数组中。

使用和函数的组合:

LEFT JOIN table_topics AS nto ON FIND_IN_SET(nto.topicid, REPLACE(ns.associated, '-', ','))

类似于在CONCAT之前添加一个“-”并将第一个“%”替换为“%-”…如果我将第一个%替换为-,则不会读取主题id 8,因为在它之前没有-,请检查表\u故事和关联字段的架构。。。对于奇怪的数据库架构;-)