Morpheusweb.it - Risorse per webmaster: script, ASP.NET, C#, Visual Basic .Net, tutorial, asp, javascript, css, php, html, java, ADO, VBScript, forms, frames, Active Server Pages, Dynamic HTML, database, gratis per webmaster e webdesigner

Banner Rotator con Statistiche

ASP banner rotator che memorizza le URLs delle immagini, links, viste, e clicks in un database Access.


<%
gblConnectString = "DBQ=" & Server.Mappath("\databases\ads.mdb") & ";Driver={Microsoft Access Driver (*.mdb)};"
gblSeparator = "#?|?#"
Response.Buffer = True

fID = Request.Item("fID")
fURL = Request.Item("fURL")
fClick = cbool(Request.Item("fClick"))
fAdmin = cbool(Request.Item("fAdmin"))
fUser = Request.Item("fUser")
fpassword = Request.Item("fPassword")
fperpage= cint(Request.Item("fperpage"))
fcurrentpage = cint(Request.Item("fcurrentpage"))
if fcurrentpage = 0 then fcurrentpage = 1
if fperpage = 0 then fperpage = 10
fsortby = Request.Item("fsortby")
fordertype = Request.Item("fordertype")
if fordertype = "" then fordertype = "ASC"
if fsortby = "" then fsortby = "ID"
'on error resume next

Set ObjCon = Server.CreateObject("ADODB.Connection")
ObjCon.Open gblConnectString,,16
Set Objcmd = Server.CreateObject("ADODB.Command")
Objcmd.ActiveConnection = ObjCon

if fAdmin = True then
  showstats fperpage, fcurrentpage, fsortby,fordertype
end if

if fClick = True and fAdmin = False then
  AdClicked fID
elseif fClick = False And fAdmin = False then
  Randomize
  Rand = cint(int(cint(AdCount) * Rnd(47) + 1))
  LoadAd Rand
end if

Sub LoadAd(intID)
  Objcmd.commandtext = "SELECT * FROM ADS WHERE ID=" & intID
  set ObjRS = Objcmd.Execute
  If ObjRS.EOF Then Response.Write("ERROR: EOF") : Exit Sub
  fID = intID
  fURL = ObjRS("URL")
  fURL = mid(fURL,10,len(fURL)-11)
  fIMG = ObjRS("ImageURL")
  fTrackURL = ObjRS("TrackURL")
  fViews = ObjRS("Views")
  fViews = fViews + 1
  Objcmd.commandtext = "UPDATE ADS SET Views=" & fViews & " WHERE ID=" & intID
  set ObjRS = Objcmd.Execute
  displayad fID,fIMG,fURL,fTrackURL
End Sub

Sub AdClicked(intID)
  Objcmd.commandtext = "SELECT Clicks FROM ADS WHERE ID=" & intID
  set ObjRS = Objcmd.Execute
  Ig ObjRS.EOF Then Exit Sub
  fID = intID
  fClick = ObjRS("Clicks")
  fClick = cint(fClick) + 1
  Response.Write furl
  Objcmd.commandtext = "UPDATE ADS SET Clicks=" & fClick & " WHERE ID=" & intID
  set ObjRS = Objcmd.Execute
  Response.Redirect furl
End Sub

Sub ShowStats(iPerPage,iCurrentPage,strSortBy, strOrderType)
  Dim TotalPages
  TotalPages = cint(Round(AdCount / iPerPage ,0))
  Objcmd.commandtext = "SELECT * FROM ADS ORDER BY " & strSortBy & " " & strOrderType
  set ObjRS = Objcmd.Execute
  'Response.Write iperpage & "&nbsp;" & icurrentpage
  ObjRS.PageSize = iPerPage
  'Response.Write TotalPages
  'ObjRS.AbsolutePage = iCurrentPage
  'Display PREV page link, if appropriate
  If Not iCurrentPage = 1 Then
    Response.Write "<div align=center><a href=ad.asp?fordertype=" & strOrdertype &_
      "&fsortby=" & strsortby & "&fcurrentpage=" & iCurrentPage - 1 &_
      "&fAdmin=True&fperpage=10>Prev</a> | "
  Else
    Response.Write "<div align=center>Prev | "
  End If
  'Display NEXT page link, if appropriate
  If cint(iCurrentPage) < TotalPages Then
    Response.Write "<a href=ad.asp?fordertype=" & strOrdertype & "&fsortby=" &_
      strsortby & "&fcurrentpage=" & iCurrentPage + 1 &_
      "&fAdmin=True&fperpage=10>Next</a><br>" & vbcrlf & "</div>"
  Else
    Response.Write "Next<br>" & vbcrlf & "</div>"
  End If
  %>
  <p><b>
  <font size="2" face="Verdana">Displaying page <%=iCurrentPage%> of <%=TotalPages%><br>
  Sorted By <%=strSortBy%>:</font>
  </b></p>
  <table align=center border=0 cellpadding=0 cellspacing=0 width="90%">
  <tr bgcolor="Silver">
  <td align=center>
  <b><a href="ad.asp?fordertype=ASC&fsortby=ID&fcurrentpage=<%=iCurrentPage%>&fAdmin=True&fperpage=10">ID</a></b>
  </td>
  <td align=center>
  <b>Image</b>
  </td>
  <td align=center>
  <b>
     <a href="ad.asp?fordertype=DESC&fsortby=Views&fcurrentpage=<%=iCurrentPage%>&fAdmin=True&fperpage=10">
     Views
      </a>
  </b>
  </td>
  <td align=center>
  <b><a href="ad.asp?fordertype=DESC&fsortby=Clicks&fcurrentpage=<%=iCurrentPage%>&fAdmin=True&fperpage=10">Clicks</a></b>
  </td>
  </tr>
  <%
  pCount = (IPerPage * iCurrentPage)
  Count = ((iperpage * icurrentpage) - iperpage)
  'Response.Write pCount & "&nbsp;" & Count
  ObjRS.Move Count
  Do While Not ObjRS.EOF and Count < Pcount
    tID = ObjRS("ID")
    tIMG = ObjRS("ImageURL")
    tViews = ObjRS("Views")
    tClick = ObjRS("Clicks")
    %>
    <tr bgcolor="Background">
    <td align=center>
    <b><%=tID%></b>
    </td>
    <td align=center valign=middle>
    <%=tIMG%>
    </td>
    <td align=center>
    <b><%=tViews%></b>
    </td>
    <td align=center>
    <b><%=tClick%></b>
    </td>
    </tr>
    <%
    objrs.MoveNext
    Count = Count + 1
  Loop
  %>
  </table>
  <%
End Sub

Sub DisplayAd(intID,strImage,strURL,strTrack)
  %><!--Start banner for ID <%=intID%> -->
  <A href="/ads/ad.asp?fID=<%=intID%>&fURL=<%=server.URLEncode(strURL)%>&fClick=True"   target="_AD"><%=strImage%><br><%=strTrack%>
  <%
End Sub

Function ADCount()
  Objcmd.commandtext = "SELECT Views FROM ADS"
  set ObjRS = Objcmd.Execute
  AdCount = 0
  do while not ObjRS.EOF
    AdCount = AdCount + 1
    ObjRS.MoveNext
  Loop
End Function

ObjCon.Close
set ObjRS = Nothing
Set ObjCon = Nothing
Set Objcmd = Nothing
%>


Nell'allegato c'è anche il database.


Scarica il Codice...


Stampa la pagina


 








Inizio pagina

risorse per webmaster