...

View Full Version : Counting Links with ASP



andyandyp
07-09-2002, 10:35 PM
Is it possible that when a link is click by the surfer a new window pops up with the website and link is counted in a database.

I am trying to get it to have some links, and the most popular one at the top of the list.

I have the connection to the database (dsn-less) and have a method of sorting the links its just counting the number of times press i am stuck on.

ahmedsoliman
07-09-2002, 11:04 PM
it work with meny link such as shoping site ,and each product has hit counter
<a herf=productdisplay.asp?id>some product</a>

andyandyp
07-10-2002, 11:17 AM
Sorry i have given the impression that i know more then you think.
I have set the links up on a page as you said
<a href="countLinks.asp?url=actual.url">link text</a>

And am not really sure were to go from there.

This is my guess
<%
Dim con, rs, strLink
Set con = Server.CreateObject("ADODB.Connection")
Set rs = Server.CreateObject("ADODB.Recordset")
con.Provider = "Microsoft.Jet.OLEDB.4.0"
con.Open "Data Source = " & Server.MapPath ("db\mydatabase.mdb")

Set rs = con.Execute("Select pageurl, hits From tuning Where URL = " & Request.Querystring("pageurl"))

strLink = rs("link")
Set rs = con.Execute("Update tuning Set hits_out = (hits_out + 1) Where pageurl = " & Request.Querystring("pageurl"))
Set rs = Nothing
con.Close
Set con = Nothing
Response.Redirect "http://" & strLink
%>

andyandyp
07-10-2002, 05:12 PM
Microsoft JET Database Engine error '80040e10'

No value given for one or more required parameters.

/nimblenova/countLinks.asp, line 9 In Red

is the error i get with that.

From this

<%
Dim con, rs, strLink
strLink = Request.Querystring("url")
Set con = Server.CreateObject("ADODB.Connection")
Set rs = Server.CreateObject("ADODB.Recordset")
con.Provider = "Microsoft.Jet.OLEDB.4.0"
con.Open "Data Source = " & Server.MapPath ("db\mydatabase.mdb")

Set rs = con.Execute("Update tuning Set hits_out = (hits_out + 1)
Where pageurl = " & strLink)
Set rs = Nothing
con.Close
Set con = Nothing
Response.Redirect strLink
%>

I have made sure that in my database "hits_out" is there and i also have "PageURL" in there

andyandyp
07-10-2002, 08:47 PM
I am not sure what this error means and how to solve it

glenngv
07-11-2002, 03:22 AM
just an alternative solution that updates link counts on the background while opening the link. This goes directly to the specified url (no redirection) without the user knowing countLinks.asp is executed on the background.

<head>
<script>
function openURL(url){
var count = new Image();
count.src="countLinks.asp?url="+url;
location.href=url;
}
</script>
</head>
<body>
<a href="javascript:link1.asp">link 1</a>
<a href="javascript:link2.asp">link 2</a>



countLinks.asp:
<%
Dim con, rs, strLink
strLink = Request.Querystring("url")
Set con = Server.CreateObject("ADODB.Connection")
Set rs = Server.CreateObject("ADODB.Recordset")
con.Provider = "Microsoft.Jet.OLEDB.4.0"
con.Open "Data Source = " & Server.MapPath ("db\mydatabase.mdb")

Set rs = con.Execute("Update tuning Set hits_out = (hits_out + 1) Where pageurl = " & strLink)
Set rs = Nothing
con.Close
Set con = Nothing
%>

glenngv
07-11-2002, 05:13 AM
sorry, maybe i was too eager to post it.
here's the correct link:

<a href="javascript:openURL('link1.asp')">link 1</a>
<a href="javascript:openURL('link2.asp')">link 2</a>

andyandyp
07-11-2002, 01:07 PM
I have now tried them both and its not working. I had a play with the script and its still didn't work.

How can i verify my ADO code and i guess its somthing to do with the access database?

andyandyp
07-11-2002, 03:51 PM
That still shows this

Microsoft OLE DB Provider for ODBC Drivers error '80004005'

[Microsoft][ODBC Microsoft Access Driver] Could not find file '(unknown)'.

/nimblenova/countlinks.asp, line 7

so it just my connection to the database that is the problem

Set con = Server.CreateObject("ADODB.Connection")
Set rs = Server.CreateObject("ADODB.Recordset")
con.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=URL=db\mydatabase.mdb"
rs.Open "tuning", con, 2, 2, 2 ' adOpenDynamic, adLockPessimistic, adCmdTable

I don't know what all the con, 2, 2, 2 ' adOpenDynamic, adLockPessimistic, adCmdTable means.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum