...

View Full Version : Item Counter Help



dawilis
07-28-2002, 08:52 AM
I have a small classifieds site Im putting together I want to count the number of times an item has been viewed.

http://www.bunburyonlineclassifieds.com.au/Showall.asp

if you go to the link you will notice that when an item is clicked it passes its 'id' through to showitem.asp and I use request.querystring(id) to display the product.
this is where I want to update the d/b 'view' table by + 1 each time its viewed
Id like it to happen in the background. any help is greatly appreciated.

raf
07-30-2002, 11:00 AM
I don't know if I understood your problem corrctly, but it doesn't seem that difficult to me.
If you select the productinfo from a table, you use your open connection to make a second recordset (lets say rsItemviews) with a selection query like

sql="select number from views where ID=anyID"
sql=replace(sql,"anyID",request.querystring(id))

Where number is the control in your table that reflect the number of times the page was displayed
Then just pick up the value from the recordset (initialy it will be 0)
like this

dim itemviews
itemviews=rsItemviews.Fields("number")
itemviews=itemviews+1

then update the record in your views table.

sql="update views set number=newnumber where id=anyID"
sql=replace(sql,"newnumber",itemviews)
sql=replace(sql,"anyID",request.querystring(id))

then close recordsets and set to nothing.

all this runs in the background an your users won"t see a thing, unless you include the number of views in your page ( respons.write(itemviews) )

I hope this will help you.

dawilis
07-30-2002, 04:59 PM
Thanks for your help sometimes its a metter of just getting your head around it, Problem solved
Daryl

raf
07-31-2002, 08:44 AM
your welcome.

I dreamt up an even better way:)

just use

sql=update pages set pages.number = pages.number+1 where pages.ID=anyID
sql=replace(sql,"anyID",request.querystring(id))

(where pages is the table that the pageview-numbers are stored in)

It'll speed up things



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum