Author Topic: Any good ASP programmers here? Need help.  (Read 2140 times)

Monkeyleg

  • friend
  • Senior Member
  • ***
  • Posts: 14,589
  • Tattaglia is a pimp.
    • http://www.gunshopfinder.com
Any good ASP programmers here? Need help.
« on: March 19, 2005, 01:42:44 PM »
Many of the owners of the subscribing gun shops on my site have asked if I would add a feature that allows them to know how many visitors have looked at their page on the site.

Right now, if someone clicks on the star next to a shop, they're linked to something like www.gunshopfinder.com/bytownresults.asp?ID=3984.

What I'd like is a piece of script that would increase by 1 the number in the Pageviews field in the database everytime someone goes to that particular ID page.

I've been looking for sample scripts all over the internet that I could somehow "Frankenstein" together, but haven't had any luck.

If anyone here knows how to write such a script, please post here or email me at admin@gunshopfinder.com. If you'd like compensation, please let me know how much.

Using ASP on a MS SQL Server database.

Thanks in advance for any replies and/or emails.

Phantom Warrior

  • friend
  • Senior Member
  • ***
  • Posts: 926
Any good ASP programmers here? Need help.
« Reply #1 on: March 19, 2005, 07:44:01 PM »
I'm neither an ASP programmer nor real experience with this stuff.  But I've worked w/ it a little (in Perl).  The thought that comes to my mind is this:  

Run a query on the database to get the record for that ID page.
Get the Pageviews field out of it.
Increment by one.
Run another query storing the updated value back in the record.

It's not efficent, but it'll work unless you're expecting super heavy traffic.  I dunno, maybe it'll get the discussion going...

jefnvk

  • friend
  • Senior Member
  • ***
  • Posts: 1,478
  • I'll sleep away the days and ride the nights...
Any good ASP programmers here? Need help.
« Reply #2 on: March 19, 2005, 07:54:38 PM »
Haven't touched ASP in a year or so.

I'd imagine you are already pulling the data out of a database.  Grab that field, too.  Assign it to a variable.  Add one to that variable.  Send that number back to the DB.

Sorry I can't help you with the code more, I'm tapped out right now.

If someone else can't help you, maybe if you stick the code up, I can help you cobble something together.
I still say 'Give Detroit to Canada'

GigaBuist

  • friends
  • Senior Member
  • ***
  • Posts: 4,345
    • http://www.justinbuist.org/blog/
Any good ASP programmers here? Need help.
« Reply #3 on: March 20, 2005, 11:56:30 AM »
No no no no... you guys got it all wrong. Smiley

First, I don't remember the details anymore.  I presume you're already doing -SOME- kind of DB access and the details should be easy to iron out with a good ADO reference handy.

Don't put the logic for incrementing the pageview counter in the ASP/VBScript.  Tempting, but perhaps not appropriate.  You could end up with a race condition at some point in time... yes this sounds uber-paranoid... but you should get into the habit of doing things right the first time all the time. Smiley

Cook up a stored procedure to do the incrementing.  You'll have to figure out on your own how to verify that the stored proc is constructed in a manner that leaves the actual increment entirely atomic.  I -believe- that a simple UPDATE statement will be atomic.  

If you retreive, modify, and store without the operation (known as the critical secton) up in a semaphore of some kind then you could run into race conditions.. and that'll give bad data.  Especially if you do it all the way up in the ASP/VBScript layer.  

You could probably do the UPDATE statement from the VBScript layer, truth be told, but I prefer to use stored procedures rather than lop all of the schema information and SQL statements up in the uppermost levels of the app.

Although... with all THAT said I reallly hate using code to keep track of hit counts and such.  A far better method, IMHO, is to parse log files to get the actual data.  I've seen plenty of clients use them as the end-all-be-all of traffic counters when in reality they give you almost NOTHING of value... just a warm fuzzy feeling that may or may not mean anything.

Monkeyleg

  • friend
  • Senior Member
  • ***
  • Posts: 14,589
  • Tattaglia is a pimp.
    • http://www.gunshopfinder.com
Any good ASP programmers here? Need help.
« Reply #4 on: March 20, 2005, 01:15:11 PM »
GigaBuist, lots of Greek in your post. Wink

Care to speak English?

I could use a stored procedure. However, I'd still have to know how to write that procedure.

Phantom Warrior

  • friend
  • Senior Member
  • ***
  • Posts: 926
Any good ASP programmers here? Need help.
« Reply #5 on: March 20, 2005, 07:51:16 PM »
*dredges up his Database Management Systems knowledge from last year*

I'm not sure if I'm getting exactly the right condition.  I think the concern is that other processes might be accessing the data at the same time and they would interfere with each other.  The classic example is the "lost update" where two processes read the same value from a variable, then both perform an operation on the value, and store it back in the variable.  If the two processes aren't interleaved properly the second process to write to the variable will overwrite the change made by the first one, causing a lost update.

GigaBuist can probably give you a better explanation than me.