Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Jul 2002
    Location
    Bunbury W.A
    Posts
    157
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Item Counter Help

    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.

  • #2
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #3
    Regular Coder
    Join Date
    Jul 2002
    Location
    Bunbury W.A
    Posts
    157
    Thanks
    0
    Thanked 0 Times in 0 Posts

    thank you

    Thanks for your help sometimes its a metter of just getting your head around it, Problem solved
    Daryl

  • #4
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •