Forums
This topic is locked
count db value +1 without reading current value
12 Apr 2002 07:58:08 Tom Ka posted:
<font face='Arial'>HelloI publish artikels on a site and want to have a simple DB-based counter.
My idea is, that every time a guest views a page a numeric db-field will count +1 . (something like articelviews +1 by artikelID)
my question: is it possible to do this without reading the current value out of the db, adding +1 with asp and updating the db?
So: just a code which opens the db and give the counterfield +1 appropriate to the articelID ???
Thanks for your help
Tom</font id='Arial'>
Replies
Replied 12 Apr 2002 17:32:23
12 Apr 2002 17:32:23 David Behan replied:
This might be what you are looking for. Insert something like this before your head tag...
<%
Dim rsProperty__MMColParam
rsProperty__MMColParam = "1"
if (Request.QueryString("property_id" <> "" then rsProperty__MMColParam = Request.QueryString("property_id"
if(rsProperty.Fields.Item("hits".Value + 1 <> "" then propertyhits__MM_NewHits = rsProperty.Fields.Item("hits".Value + 1
%>
<%
set propertyhits = Server.CreateObject("ADODB.Command"
propertyhits.ActiveConnection = MM_property_STRING
propertyhits.CommandText = "UPDATE tbl_listing SET hits = " + Replace(propertyhits__MM_NewHits, "'", "''" + " WHERE property_id = " + Replace(propertyhits__MMColParam, "'", "''" + ""
propertyhits.CommandType = 1
propertyhits.CommandTimeout = 0
propertyhits.Prepared = true
propertyhits.Execute()
%>
Just some script I set up ages ago to such a thing. Try it and see. It was built using the stored procedures in UD.
Regards
_________________________
David Behan - www.bmor.com
<%
Dim rsProperty__MMColParam
rsProperty__MMColParam = "1"
if (Request.QueryString("property_id" <> "" then rsProperty__MMColParam = Request.QueryString("property_id"
if(rsProperty.Fields.Item("hits".Value + 1 <> "" then propertyhits__MM_NewHits = rsProperty.Fields.Item("hits".Value + 1
%>
<%
set propertyhits = Server.CreateObject("ADODB.Command"
propertyhits.ActiveConnection = MM_property_STRING
propertyhits.CommandText = "UPDATE tbl_listing SET hits = " + Replace(propertyhits__MM_NewHits, "'", "''" + " WHERE property_id = " + Replace(propertyhits__MMColParam, "'", "''" + ""
propertyhits.CommandType = 1
propertyhits.CommandTimeout = 0
propertyhits.Prepared = true
propertyhits.Execute()
%>
Just some script I set up ages ago to such a thing. Try it and see. It was built using the stored procedures in UD.
Regards
_________________________
David Behan - www.bmor.com