"浏览过该文章的还有""我的好友浏览过的文章"
//浏览记录添加(每次浏览日志添加一条记录)
if($_SGLOBAL['supe_uid']) {
$uid=$_SGLOBAL['supe_uid'];
$aid=$_GET['id'];
if($aid) {
$setarr = array(
'uid' => $uid,
'aid' => $aid
);
inserttable('lookhis', $setarr, 0, true);
}
}
//浏览过该文章的有
$visitorlist = array();
$query = $_SGLOBAL['db']->query("SELECT l.*,s.spacename FROM ".tname('lookhis')." l LEFT JOIN ".tname('space')." s ON s.uid=l.uid WHERE l.aid='$aid' group by spacename");
while ($value = $_SGLOBAL['db']->fetch_array($query)) {
$visitorlist[] = $value;
}
//选出我的好友
$friend = array();
$query = $_SGLOBAL['db']->query("SELECT f.fuid FROM uch_lookhis l LEFT JOIN uch_friend f ON f.uid=l.uid WHERE l.uid=$_SGLOBAL[supe_uid] group by fuid");
while ($val = $_SGLOBAL['db']->fetch_array($query)) {
$friend[] = $val['fuid'];
}
$result = implode(",",$friend); //implode用法见后面说明
//我的好友浏览过的文章
$visitorar = array();
$query = $_SGLOBAL['db']->query("SELECT l.*,b.subject,b.blogid,b.uid buid FROM ".tname('lookhis')." l LEFT JOIN ".tname('blog')." b ON b.blogid=l.aid WHERE l.uid in ($result) group by subject"); //WHERE l.uid in ($result)中$result是用“,”隔开的fuid
while ($valu = $_SGLOBAL['db']->fetch_array($query)) {
$visitorar[] = $valu;
}
静态页
浏览过该文章的还有:
<!--{loop $visitorlist $value}-->
<!--{if $value[uid]!=$_SGLOBAL[supe_uid]}--> 此判断用于把自己剔除出去
<a href="space.php?uid=$value[uid]">$value[spacename]</a>
<!--{/if}-->
<!--{/loop}--><br />
我的好友浏览过的文章标题:
<!--{loop $visitorar $valu}-->
<a href="space.php?uid=$value[buid]&do=blog&id=$valu[blogid]">$valu[subject];</a>
<!--{/loop}-->
函数解释:
- <?php
- $array = array('lastname', 'email', 'phone');
- $result = implode(",", $array);
- echo $result ; // lastname,email,phone
- $string = 'jpg|gif|png';
- $result = explode('|',$string);
- print_r($result); //array('jpg','gif','png')
- ?>
<?php $array = array('lastname', 'email', 'phone'); $result = implode(",", $array); echo $result ; // lastname,email,phone $string = 'jpg|gif|png'; $result = explode('|',$string); print_r($result); //array('jpg','gif','png') ?>
implode,explode是常用的将数组和字符串之间转换的函数
implode 将数组以一个字符连接成字符串
explode 使用一个字符串分割另一个字符串