我想列出访问者的IP地址和上次冲浪网址。我编码的以下代码可以很好地期待一件事。它不会列出最后一个URL地址,而是列出所有这些地址。例如:
71.187.189.67 | 7/6/2009 9:59:25 PM | /html/default.aspProcess=HomeNewSeason& IMAGECONTENT = bg_home_newtaste.gif更多...... 71.187.189.67 | 7/6/2009 9:59:24 PM | /html/default.aspMore ... 66.249.68.210 | 7/6/2009 9:51:32 PM | /html/default.aspSection=products& SubSection = products& CATEGORYID = 2& SORTBY = PriceDownMore ...
但我希望它为
71.187.189.67 | 7/6/2009 9:59:25 PM | /html/default.aspProcess=HomeNewSeason& IMAGECONTENT = bg_home_newtaste.gif更多...... 66.249.68.210 | 7/6/2009 9:51:32 PM | /html/default.aspSection=products& SubSection = products& CATEGORYID = 2& SORTBY = PriceDownMore ...
我的代码
<%
OnlineTime = DateAdd("n", -10, Now())
SQL = "SELECT COUNT(DISTINCT VISITORIP) AS ONLINE, VISITORIP, HTTPADDRESS, DATEENTERED"
SQL = SQL & " FROM STATS"
SQL = SQL & " WHERE DATEENTERED BETWEEN '" & OnlineTime & "' AND '" & NOW() & "'"
SQL = SQL & " GROUP BY VISITORIP, HTTPADDRESS, DATEENTERED"
SQL = SQL & " ORDER BY DATEENTERED DESC"
Set objOnVisitors = objConn.Execute(SQL)
If objOnVisitors.EOF Then
Else
%>
<!-- Start Post -->
<div class="post">
<div class="date">
<span class="month">Online</span>
<span class="day"><%=objOnVisitors("ONLINE")%></span>
</div>
<p>
<span class="title">Visits Online</span>
</p>
<% Do While Not objOnVisitors.EOF %>
<p>
<%=objOnVisitors("VISITORIP")%>|<%=objOnVisitors("DATEENTERED")%>|<%=objOnVisitors("HTTPADDRESS")%><a href="">More...</a>
</p>
<%
objOnVisitors.MoveNext
Loop
%>
</div>
<!-- End Post -->
End If
objOnVisitors.Close
Set objOnVisitors = Nothing
%>
答案 0 :(得分:2)
此查询应该这样做。语法可能有点不对。我正在创建一个内部查询来查找MAX(DATEENTERED),并将其连接到STATS以将结果限制为每个IP的最新结果。
SQL = "SELECT S.VISITORIP, S.HTTPADDRESS, S.DATEENTERED"
SQL = SQL & " FROM STATS S"
SQL = SQL & " JOIN (SELECT VISITORIP, MAX(DATEENTERED) FROM STATS S WHERE DATEENTERED BETWEEN '" & OnlineTime & "' AND '" & NOW() & "') S1"
SQL = SQL & " ON S.VISITORIP = S1.VISITORIP AND S.DATEENTERED = S1.DATEENTERED"
SQL = SQL & " WHERE S.DATEENTERED BETWEEN '" & OnlineTime & "' AND '" & NOW() & "'"
SQL = SQL & " GROUP BY S.VISITORIP, S.HTTPADDRESS, S.DATEENTERED"
SQL = SQL & " ORDER BY S.DATEENTERED DESC"