簡體   English   中英

使用SQL查詢獲取所有標簽

[英]get all tags with sql query

我有這個由別人幫助的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 ";

結果是這樣的(我在這里只顯示一個入口,可能更多):

[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
        )

對於標簽,我必須顯示一個實體擁有的所有標簽,並突出顯示用於獲取結果的標簽。 在這種情況下, [tag_list] => tree僅顯示一個標簽,即在搜索字段中使用的標簽。 我的問題是,我怎么能得到這樣的結果?:

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

作為一個數組也很好,但是當它只是一個項目時,還請一個數組。

如果我理解正確,則在條件中使用> =

$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 ";

子查詢方法:

$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
 ";

進入子查詢,我得到至少請求標簽的entrie havin的ID列表,然后在主查詢中,我得到所有的infox

添加固定查詢(請參閱問詢者評論)

子查詢方法,修復“ 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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM