D2 r- s& V q * g* V, B! h0 V ( o$ K4 m& R# [# g 在表格标签中添加另一列作为计数器。在项目中添加或删除标签时,您会更新计数器(换句话说,在Itemtag上添加一行时,在Tag表上增加计数器,而在删除时减少计数器)! T: c$ L2 G( n+ q7 C' o) [
将标签添加到项目: " n$ s( D ?( @INSERT INTO Itemtag (itemid,tagid) VALUES ('$itemid','$tagid'); " V- G2 k9 H4 n; c, ~+ x; XUPDATE Tag SET counter=counter+1 WHERE tagid='$tagid'; % H8 i1 U" b6 A. Z从项目中删除标签 4 C7 F# F/ R$ E! T. U# ~, S" r( B' WDELETE FROM Itemtag WHERE itemid='$itemid' AND tagid='$tagid'; * W1 J) Q4 U4 m* _, hUPDATE Tag SET counter=counter-1 WHERE tagid='$tagid'; ; l# N$ b0 e. j* n7 `使用计数器检索商品标签 " \$ b' _6 }# E' J# c6 ~0 m8 YSELECT t.title, t.counter FROM Itemtag AS it JOIN Tag AS t ON t.idtag=it.tagid / q d% l2 b; L( C( V$ e% YWHERE it.itemid='$itemid'