首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

怎么实现BLOG 记录最近访客?

2012-03-08 
如何实现BLOG 记录最近访客???如何解决BLOG记录最近访客的问题?? 怎么实现呢??今天脑袋不好使。想不起来怎

如何实现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
------解决方案--------------------


if(userID!=dt.Rows[0]["uid"].ToString())//两个用户ID不相等的话则记录为访客
{
//从这里开始改一下,最好就用一个sql解决就好,逻辑大概如下
if exists(select * from table1 where field1='123' )--如果该访客之前有记录,则更新此记录即可
update table1 set field1='aaaaa'
else
begin
insert into table1 (field1)values('bbbb');---插入记录
delete from table1 where ....;---删除最早的记录
end
}

[解决办法]
就是临时表,按时间保留最新的15条!
[解决办法]
楼上用SQL实现的可行
[解决办法]
根据登陆时间字段里的值,取最后登录的15个不是更简单吗?

热点排行