$tagval=$dsql->getOne("SELECT tag FROM `#@__tagindex` WHERE id=$tag")['tag']; $t=mb_substr($tagval,0,4,'utf-8'); $t2=mb_substr($tagval,0,2,'utf-8'); //获得与当前tag相关的tag数据 $res1=$dsql->getData("SELECT id,tag FROM `#@__tagindex` WHERE tag like '%$t%' and id!=$tag and total>0 limit 8"); $ids=''; if(count($res1)<8){ foreach($res1 as $k){ $ids.=$k['id'].','; } $ids=$ids.$tag; $limit=8-count($res1); $res2=$dsql->getData("SELECT id,tag FROM `#@__tagindex` WHERE tag like '%$t2%' and id not in($ids) and total>0 limit $limit"); $res=array_merge($res1,$res2); } else{ $res=$res1; } $artarr1=$dsql->getData("SELECT DISTINCT a.id,a.shorttitle FROM `#@__archives` as a left join `#@__taglist` as b on b.aid=a.id WHERE a.title like '%$t%' and b.tid!=$tag limit 6"); //var_dump($artarr1);die; if(count($artarr1)<6){ foreach($artarr1 as $a){ $aids.=$a['id'].','; } $aids=$aids.'0'; $limit=6-count($artarr1); $artarr2=$dsql->getData("SELECT DISTINCT a.id,a.shorttitle FROM `#@__archives` as a left join `#@__taglist` as b on b.aid=a.id WHERE a.title like '%$t2%' and a.id not in($aids) limit $limit"); $artarr=array_merge($artarr1,$artarr2); }else{ $artarr=$artarr1; }