View Full Version : Item Counter Help

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


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.

07-30-2002, 10: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"

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

then update the record in your views table.

sql="update views set number=newnumber where id=anyID"

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.

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

07-31-2002, 07: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

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

It'll speed up things