根据另一个表上的相关csv id从表中获取行

时间:2022-08-24 21:38:52

I've been running a mysql query to get all rows based on FIND_IN_SET($bannerpageid,bf_relatedid)

我一直在运行一个mysql查询来获取基于FIND_IN_SET的所有行($ bannerpageid,bf_relatedid)

$bannerpageid is a php variable declared at the top of each page.

$ bannerpageid是在每个页面顶部声明的php变量。

banner_frames

  bf_ID  bf_relatedID   bf_content
  1      1,2,3,4        content
  2      2,4,6,8,10     content
  3      1,3,5,7,9      content
  ...

So $bannerpageid = 3, it would return rows 1 and 3 from the banner_frames table

所以$ bannerpageid = 3,它会从banner_frames表中返回第1行和第3行

It works, but it feels kind of backwards, I feel it would be better if the related bf_IDs were declared in a separate table banner page table. It would make the related id's easier to manage in the long run.

它有效,但感觉有点倒退,我觉得如果在单独的表标题页表中声明相关的bf_ID会更好。从长远来看,它会使相关的id更容易管理。

banner_page

  bp_ID  bp_relatedID
  1      1,2,3,4
  2      2,4,6,8,10
  3      1,3,5,7,9
  ...

banner_frames

  bf_ID  bf_content
  1      content
  2      content
  3      content
  ...

This time $bannerpageid relates to bp_ID in the banner_page table, so if $bannerpageid = 3, it would return rows 1 and 3 from the banner_frames table

这次$ bannerpageid与banner_page表中的bp_ID有关,因此如果$ bannerpageid = 3,它将从banner_frames表返回第1行和第3行

I tried to write the mysql query to find in set based on a inner join, but I couldn't get it to execute the query correctly. So I'm a bit stumped.

我尝试编写mysql查询以基于内部联接在集合中查找,但我无法让它正确执行查询。所以我有点难过。

If anyone has any suggestions I'd be really appreciative

如果有人有任何建议我会非常感激

Thanks

1 个解决方案

#1


0  

What is your original MySQL code based on FIND_IN_SET?

基于FIND_IN_SET的原始MySQL代码是什么?

Try with:

 SELECT banner_frames.bf_content FROM banner_frames JOIN banner_page ON (banner_page.bp_ID = banner_frames.bf_ID) WHERE FIND_IN_SET($bannerpageid, banner_page.bp_relatedID)

#1


0  

What is your original MySQL code based on FIND_IN_SET?

基于FIND_IN_SET的原始MySQL代码是什么?

Try with:

 SELECT banner_frames.bf_content FROM banner_frames JOIN banner_page ON (banner_page.bp_ID = banner_frames.bf_ID) WHERE FIND_IN_SET($bannerpageid, banner_page.bp_relatedID)