简体   繁体   English

使用SQL查询获取所有标签

[英]get all tags with sql query

I have this sql that is made by help of others. 我有这个由别人帮助的sql。

$sql ="
select e.*, i.*, group_concat( t.tag separator ',') as tag_list
from nv_entries e
JOIN nv_tags t on t.entrie_id = e.id
LEFT JOIN nv_images i on i.entrie_id = e.id

where t.tag in ( $tag_list )
group  by e.id
having count(t.id) = $num_tags ";

The result is this (i only show one entrie here, could be more): 结果是这样的(我在这里只显示一个入口,可能更多):

[1] => Array
        (
            [id] => 2
            [band] => Kids for Cash
            [album] => No More Walls E.P.
            [label] => 
            [year] => 1986
            [text] => Text about album kids for cash.
            [entrie_id] => 2
            [source] => img02_9lch1.png
            [tag_list] => tree
        )

For the tags, i have to show all tags that a entrie has and highlight the tags that where used to get the result. 对于标签,我必须显示一个实体拥有的所有标签,并突出显示用于获取结果的标签。 In this case [tag_list] => tree only shows one tag, the one that was used in the search field. 在这种情况下, [tag_list] => tree仅显示一个标签,即在搜索字段中使用的标签。 My question is, how can i get a result like this?: 我的问题是,我怎么能得到这样的结果?:

            ...
            [tag_list] => tree, green, foo, bar
            [used_tags] => tree
        )

As a array is also good, but then please also an array when it's just one item. 作为一个数组也很好,但是当它只是一个项目时,还请一个数组。

If I understood correctly use >= in the having condition 如果我理解正确,则在条件中使用> =

$sql ="
select e.*, i.*, group_concat( t.tag separator ',') as tag_list
from nv_entries e
LEFT JOIN nv_images i on i.entrie_id = e.id
JOIN nv_tags t on t.entrie_id = e.id

where t.tag in ( $tag_list )
group  by e.id
having count(t.id) >= $num_tags ";

ADD

subquery approach: 子查询方法:

$sql ="
select e.*, i.*, group_concat( t.tag separator ',') as tag_list
from nv_entries e
JOIN nv_tags t on t.entrie_id in (
select se.id 
from nv_entries se
JOIN nv_tags st on st.entrie_id = se.id

where st.tag in ( $tag_list )

group  by se.id
having count(st.id) >= $num_tags

)
    LEFT JOIN nv_images i on i.entrie_id = e.id
    WHERE 1
    group by e.id
 ";

Into subquery I get the ID list of entrie havin at least requested tags, then in main query I get all infox 进入子查询,我得到至少请求标签的entrie havin的ID列表,然后在主查询中,我得到所有的infox

ADD fixed query (see asker comment) 添加固定查询(请参阅问询者评论)

subquery approach, fix the lost join between "e" and "t" : 子查询方法,修复“ e”和“ t”之间丢失的联接:

$sql ="
select e.*, i.*, group_concat( t.tag separator ',') as tag_list
from nv_entries e
JOIN nv_tags t on t.entrie_id = e.id 
    LEFT JOIN nv_images i on i.entrie_id = e.id
    WHERE e.id in  (
select se.id 
from nv_entries se
JOIN nv_tags st on st.entrie_id = se.id

where st.tag in ( $tag_list )

group  by se.id
having count(st.id) >= $num_tags

)
    group by e.id
 ";

移除所有<div tags with sql query< div><div id="text_translate"><p> 我有表名wp_posts并且在post_content列中有我的帖子的描述(HTML 格式)。</p><p> 我想要一个在 post_content 列中搜索并选择以<div class or no class>开头的标签并删除整个标签的查询。</p><p> 我不想删除标签内的任何内容,只需删除标签</p><p>这个:</p><pre> <div> or <div clas="sada"> some text </div></pre><p> 会变成这样:</p><pre> some text</pre><p> 我的 MYSQL 版本是 15.1。</p></div></div> - Remove all <div tags with SQL Query

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 移除所有<div tags with sql query< div><div id="text_translate"><p> 我有表名wp_posts并且在post_content列中有我的帖子的描述(HTML 格式)。</p><p> 我想要一个在 post_content 列中搜索并选择以<div class or no class>开头的标签并删除整个标签的查询。</p><p> 我不想删除标签内的任何内容,只需删除标签</p><p>这个:</p><pre> <div> or <div clas="sada"> some text </div></pre><p> 会变成这样:</p><pre> some text</pre><p> 我的 MYSQL 版本是 15.1。</p></div></div> - Remove all <div tags with SQL Query SQL JOIN获取名称和项目的所有标签 - SQL JOIN get name and all tags for item 查询以获取所有标签字段值并将所有值倒入字段 - Query to get a all tags field values and pour all value in field MY SQL查询,用于从字段中删除所有标签 - MY SQL Query for remove all a tags from field WP_Query按类别获取所有带有标签的帖子 - WP_Query Get all Posts by category with Tags included 获取所有相关标签? - get all related tags? SQL获取查询中所有用户活动的总和 - SQL get all users activity summed in a query 使用SQL查询获取所有Magento类别 - Get all Magento Categories using SQL query 移除所有<div>带有查询的标签</div><div id="text_translate"><p>我想从内容中删除所有<div>标签,我使用此查询,它只删除没有 class 的<div>标签,如何删除所有<div>,<div class"example">,</div> ?</p><pre> UPDATE wp_posts SET `post_content` = REPLACE (`post_content`, '<div>', '') WHERE `ID`=84259</pre><p> 我想要一个删除<%div%>的查询(% 意味着不管 div 之前和之后是什么)</p></div> - Remove all <div> tags with a query sql查询带有特定标签的帖子 - sql query for posts with specific tags
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM