日期:2014-05-18  浏览次数:20464 次

如何实现BLOG 记录最近访客???
如何解决BLOG 记录最近访客的问题?? 怎么实现呢??今天脑袋不好使。想不起来怎么做,思维混乱;
我用cookies获取凡是登陆后在访问我博客的UID并添加到数据库去了下面是我代码:
[align=left]
C# code
  cookies = Request.Cookies["UserCookies"];//记录访客

                sqls.Fill_DT("select uid from dbo.bbs_users where itemno='" + SQLUtil.FilerSql(space) + "'", dt);
                if(dt.Rows.Count>0)//根据博客编号去除用户。判断是是否本人访问进行排除
                {
                     if (cookies != null)
                        {
                            string userID = cookies["User_Uid"].ToString();
                            if(userID!=dt.Rows[0]["uid"].ToString())//两个用户ID不相等的话则记录为访客
                             {
                                 DataTable dtcaller = new DataTable();
                                //如果访客人数大于15则进行update最早那个访客
                                 sqls.Fill_DT("select * from  dbo.space_MyCaller",dtcaller);
                                 if (dtcaller.Rows.Count > 15)
                                 {
                                     DataTable dtid = new DataTable();
                                     //获取15条数据最早的一条ID并进行update
                                     sqls.Fill_DT("select callerid from dbo.space_MyCaller where callerid=(select top 1 callerid from space_mycaller)",dtid);
                                     if(dtid.Rows.Count>0)
                                     {
                                         sqlt.Operate("update dbo.space_MyCaller set datetime='" + DateTime.Now.ToString() + "',uid='" + userID + "',logitemno='" + space + "' where callerid='"+dtid.Rows[0]["callerid"].ToString()+"'");
                                         sqlt.ConClose();
                                     } sqls.ConClose();
                                 }
                                 else
                                 {
                                     sqlt.Operate("insert into dbo.space_MyCaller(datetime,uid,logitemno) values('" + DateTime.Now.ToString() + "','" + userID + "','" + space + "')"); sqlt.ConClose();
                                 }
                             }
                         
                        }
                } sqls.ConClose();
[/align]
谁还有好的代码。贴出来。分大大的有赏,注释只要代码或者很好思路。哈哈 快来抢分。

------解决方案--------------------
1.从Cookies 获取登录用户
2.先取出数据库最新的15条放到临时表 判断用户是否在记录里面
 如果存在则删除对应记录(此时剩14条了)
 然后重新添加记录到临时表(保证最新)
否则 直接添加记录 到临时表
3.清空表 space_MyCaller
4.用临时表最新的15条填充 OK了
猩猩明白了吗?
------解决方案--------------------
一个Blog有一个15个数目的值,存数据库,或者其他全局变量数据结构都可以。如果有匹配的就重新排序。没有匹配的就重新Update的一次。
------解决方案--------------------
declare @uid int
set @uid = '" + userID + "'
if exec(select * from select * from dbo.space_MyCaller where uid = @uid)
begin 
update dbo.space_MyCaller set datetime='" + DateTime.Now.ToString() + "'where uid= @uid
end 
else 
if((select count (*) fromdbo.space_MyCaller )>14)
begin
update dbo.space_MyCaller set datetime='" + DateTime.Now.ToString() + "',uid='" + userID + "',logitemno='" + space + "' where callerid= (select top 1 callerid from hsdata..Patient order by datetime asc));//这个具体你自己写
end 
else
insert into dbo.space_MyCaller(datetime,uid,logitemno) values('" + DateTime.Now.ToString() + "','" + userID + "','" + space + "')"); ju
------解决方案--------------------