Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有两个tableforarticle和setting。在table我放置的文章id,title,date ..etc和设置中table,我有一行名称featuredarticle和文章的放置id,特色文章带有单独的逗号。现在我只需要列出/打印我的特色文章。如何 ?
table
article
setting
id,title,date ..etc
featuredarticle
id
表文章:
ID | TITLE | DATE | PUBLISH 1 2 3 4 5
表设置/行精选文章:
1,2,5
SELECT a.* FROM articles a INNER JOIN settings b ON FIND_IN_SET(a.ID, b.featuredarticle) <> 0
如果您有时间更改表架构,请更改它。用逗号分隔列的值是一个糟糕的设计。
你可以试试这个-
SELECT * FROM article JOIN settings ON FIND_IN_SET( id, featuredarticle)
请看演示:demo
从数据库获取数据到数组并使用:
$newArray = explode(".", $dataDbArray);