doushi2902
2018-09-03 20:45
浏览 139
已采纳

MySQL - 如何在表中选择其中id值在另一个表的逗号分隔字段中的行?

I have been working on this problem for 3 days and am bleary eyed. I have an SQL "customers" table containing the customers name, address, email and a field called "venue" containing a comma delimited set of "id"'s of the venues of training courses they are interested in. (like: 18,22,35,41)

I have a second table called "venue" which holds the venues of all courses. Each course is a separate row in the "venue" table with an auto-increment id. The venue field in the "customers" table are a collection of the row "id" in the venue table which the customer selected at registration.

Once the customer is registered and is transported to the "my interests" page I would like to display the courses they have registered an interest in by outputting the row data of each "id" of the "venue" table that are held in the "customer.venue" field of the customer table.

I hope that makes sense...

My customer select

$sqlc = "Select * from customers ORDER BY id DESC LIMIT 1";

My venue selection

$venue = $result['venue'];

My current "venue" select code which isn't working

sqlcp = "SELECT * FROM venue WHERE FIND_IN_SET('$venue', id)";

Please ask any questions needed, thanks for looking

图片转代码服务由CSDN问答提供 功能建议

我已经解决了这个问题3天了,我很沮丧。 我有一个SQL“客户”表 包含客户姓名,地址,电子邮件和名为“场所”的字段,其中包含他们感兴趣的培训课程的逗号分隔的“id”集合(如:18,22,35,41)

我有一个名为“场地”的第二个桌子,它保存着所有课程的场地。 每个课程都是“场地”表格中的一个单独的行,带有一个自动增量ID。 场地字段 在“customers”表中,是客户在注册时选择的场地表中的行“id”的集合。

一旦客户注册并被转移到“我的兴趣”页面,我想通过输出每个“id”的行数据来显示他们注册的兴趣的课程。 在customer表的“customer.venue”字段中保存的“places”表。

我希望这是有道理的......

我的客户选择

  $ sqlc =“从客户选择* ORDER BY ID DESC LIMIT 1”; 
   
 
 

我的场地选择

  $ venue = $ result ['venue']; 
   
 
 

我目前的“场地” “选择不起作用的代码

  sqlcp =”SELECT * FROM场地WHERE FIND_IN_SET('$ venue',id)“; 
   
 
 

请提出任何问题,谢谢您的回复

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • duanmei1850 2018-09-03 21:15
    已采纳

    I think you should write this code like :

    $sqlcp = "SELECT * FROM venue WHERE FIND_IN_SET(id,'$venue')";
    
    评论
    解决 无用
    打赏 举报
查看更多回答(1条)

相关推荐 更多相似问题