<?php $v= mb_substr($navinfor[title],0,5,'UTF-8'); $id=$navinfor[id];?> [e:loop={"select * from phome_ecms_xiazai where (title like '%$v%') and id<>$id order by rand() desc limit 8",10,24,0}] <li> <span class="span_tt"><a href="<?=$bqsr['titleurl']?>" target="_blank" class="tit"><?=$bqr['title']?></a></span> <em class="ico1 xin<?=$bqr['pingfen']?>"></em> <span class="span_dx"><?=$bqr['daxiao']?></span> <a href="<?=$bqsr['titleurl']?>" target="_blank">查看详情</a> </li> [/e:loop]
说明:
第一行使用PHP函数”mb_substr”从”$navinfor[title]”中提取了前5个字符,并将结果赋值给变量”$v”。然后将”$navinfor[id]”的值赋给变量”$id”。
用灵动标签从”phome_ecms_xiazai”的数据表中查询符合特定条件like ‘%$v%’,也就是包含标题前5个字符的记录,并随机抽取8条记录进行展示。
多表联合查询:
<?php $v= mb_substr($navinfor[title],0,5,'UTF-8'); ?> [e:loop={"select * from phome_ecms_xiazai where title like '%$v%' UNION select * from phome_ecms_azsoft where title like '%$v%' UNION select * from phome_ecms_azgame where title like '%$v%' order by rand() desc limit 1",10,24,0}] <div class="s_news"> <a href="<?=$bqsr['titleurl']?>"><img class="" src="<?=$bqr['titlepic']?>"></a> <div class="t"> <div class="t-c"> <a href="<?=$bqsr['titleurl']?>"><?=$bqr['title']?></a> </div> <div class="t-b"> <span> <em>类型:<i>操作系统</i></em> <em>大小:<?=$bqr['daxiao']?></em> </span> <span> <em>评分:<i class="stars star<?=$bqr['pingfen']?>"></i></em> <em>时间:<i><?=date('Y-m-d',$bqr[newstime])?></i></em> </span> </div> </div> <div class="xz"> <a rel="nofollow" href="<?=$bqsr['titleurl']?>">立即下载</a> </div> </div> [/e:loop]